MATLAB: ODE45 2DOF Unable to perform assignment because the left and right sides have a different number of elements.

MATLABode45

Hi good people,
I'm trying to solve this:
clc
clear all
close all
x0=0;
xdot0=0;
IC=[x0 xdot0];
t=0:0.1:10;
[t,x]=ode45( @MDOF1, t, IC );
when the MDOF1 function looks like:
function dxdt=MDOF1(t,x)
m=[2 2];
M=diag(m);
C=[4 -2;-2 4];
K=[8 -4;-4 8];
F=10*sin(10*t);
dxdt(1)=x(2);
dxdt(2)=inv(M)*F-(inv(M)*C)*x(2)-(inv(M)*K)*x(1)
dxdt=[dxdt(1);dxdt(2)];
end
and i get this error:
Unable to perform assignment because the left and right sides have a different number of elements.
Error in MDOF1 (line 8)
dxdt(2)=inv(M)*F-(inv(M)*C)*x(2)-(inv(M)*K)*x(1)
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in mdof1_ode (line 8)
[t,x]=ode45( @MDOF1, t, IC );
Could anyone advise me what I'm doing wrong?

Best Answer

HI Piotr,
I decided to post one last observation as an answer, which you may respond to as you wish.
Since you have a couple of driving sine functions, the system must eventually settle down to an equilibrium state of constant amplitudes for x's and v's. My first reaction on seeing your plot was that there must be something wrong, because the solution was decaying away. However, it turns out that your initial conditions are quite large compared to equilibrium. If you run the time out to 100 seconds and zoom in, you can see equilibrium ampliudes around 10^-4, considerably smaller than your initial conditions. Or if you use IC = [0 0 0 0] you can see the system settle down quite a bit more quickly. Overall it appears that things are looking good.