Strange behavior with ODE45 dependent on tspan
Show older comments
I'm writing code to solve a simple spring mass damper system excited by a very short gaussian pulse using ode45. I've noticed that the solution varies wildly with what is given for the tspan argument. The code I've pasted uses a sample frequency of 3 times the natural frequency to generate tspan, and the resulting solution looks as expected. However if I change the sampling frequency (say to 4*omega_n), or the number of sample points N, the solution changes drastically to something widlly incorrect. I suspect the problem is in the tight timing of the gaussian pulse, as when I increase the width the solution remains stable across almost any tspan.
I'd like to know why this behavior occurs, why the one value of sf makes the solution work when no other value does, and how to prevent this problem in the future. The only reason I was able to get a valid solution was by guessing a checking different values of sf until something worked.
clear
close all
clc
% System parameters
m = 2; %(kg)
k = 1250; %(N/m)
c = 0.1; %(Ns/m)
gaussian_amp = 3; %(N)
width = 0.01; %(s)
omega_n = sqrt(k/m);
% sampling parameters
sf = 3*omega_n;
N = 5*sf;
tspan=[0:N-1]/sf;
parameters = {m,c,k,gaussian_amp,width};
[t,z] = ode45(@sDoF_solver,tspan,[0,0],[],parameters);
x = z(:,1);
v = z(:,2);
g = make_ddt_gaussian(gaussian_amp,width,1,t);
plot(t,x)
hold on
yyaxis right
plot(t,g)
function x_dot = sDoF_solver(t,x,para)
M = para{1};
C = para{2};
K = para{3};
force_amp = para{4};
width = para{5}
g = make_ddt_gaussian(force_amp,width,1,t); % using an arbitrary 1 second delay for nice looking plots
% x(1) = x
% x(2) = v
x_dot = [x(2); -C/M*x(2) - K/M*x(1) + g/M]
end
function g = make_ddt_gaussian(A,width,delay,t)
arg = -pi*((t-delay)/width).^2;
gau = A*exp(arg);
g = 4.1327*(t-delay)/width.*gau;
end
1 Comment
Bruno Luong
on 12 Apr 2024
Edited: Bruno Luong
on 12 Apr 2024
- You should devide omega by 2*pi to get the resonance period frequency (noy angular frequency) the( compute fs from that?
- You should sample correctly the pushort pulse.
- Your pulse is not Gaussion but the derivative of the Gaussian.. The total net force is 0 so it will resonate differently depending on the phase of the excitation
Accepted Answer
More Answers (0)
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
