I am simulating a mass - damper - system in Matlab and I have the following vector (1x100) as input to my system:
ut = linspace(0, 10);
u = 5 * sin(2 * ut) + 10.5; % input of our system - external force
Now, I want to take the value of the output for each value of the input vector using this differential equation:
function dx = odefun_4(t,x)
m = 15;
b = 0.2;
k = 2;
dx = [x(2); u/m - (b/m)*x(2) - (k/m)*x(1)];
end
which is called from my main .m
file like this:
[t,X] = ode45(@odefun_4, [0 10], [0;0])
I tried to pass the u
vector by making it global variable but I get an error stating: Dimensions of arrays being concatenated not consistent.
I also tried to set the Refine
parameter using odeset
and the options
argument of ode45
solver but still don't get the desired results. I could really use some help.