I'm trying to reduce a system of two second-order differential equations into a system of first-order equations, solve them, and plot the result. The differential equations are x1'' = -(k1*x1 - k2*(x1 - x2))/m and x2'' = -(k2(x2 - x1))/m2.
This is what I have so far:
[t, y] = ode45(@func,[0 100],[3, 0])
function dy = func(t,y)
m1 = 2;
m2 = 4;
k1 = 3;
k2 = 5;
dy = zeros(4,1)
dy(1) = y(2);
dy(2) = -(-(k1 + k2)*y(1)+k2*y(3))./m1;
dy(3) = y(4);
dy(4) = (k1*y(1) - k2*y(3))./m2;
It says that there is an error in line 1 and errors in ode45 and odearguments. There is also an error in line 11 and that "index exceeds the number of array elements."