I have the following 2nd order differential equations I need to solve:
x1''=(F(t)-(c1+c2)*x1'+c2*x2'-(k1+k2)*x1+k2*x2)/m1
x2''=(c2*x1'-c2*x2'+k2*x1-k2*x2)/m2
All k, c, m and F(t) are known. Derivatives are wrt time. I tried to lay it out as if it was a single 2nd order ode.
function [ xp ] = ftotal( t,x )xp=zeros(4,1)xp(1)=x(2); %x1 dot
xp(2)=(F-(c1+c2)*x(2)+c2*x(4)-(k1+k2)*x(1)+k2*x(4))/m1;xp(3)=x(5);xp(4)=(c2*x(2)-c2*x(5)+k2*x(1)-k2*x(4))/m2;end[t,x]=ode45('ftotal',[0,1],[0 0])
As expected, it gave "Index exceeds matrix dimensions". All my initial conditions are 0, I know there should be 4 (x1, x1', x2, x2'=0) but I'm not sure how to input them. I have little experience with ODE45. My goal is to obtain x1 and x1' vs t, and x2 and x2' vs t. Any help is appreciated.
Best Answer