MATLAB: Solve a variable and then the second order differential equation (ODE45)

differential equationsode45second order

Hello,
I have my dynamic equation M*q'' +C*q'+g=Tau and I created a program using ODE45 to solve q and q' as follows:
qinit=[0;0;0]; % q(0), q'(0) and q''(0)
[t,y] = ode45(@EQM,[0,1],qinit);
function dqdt = EQM(t,q)
Tau=M*q(3) +C*q(2)+g;
dqdt=[q(2);M^-1(Tau-C*q(2)-g)]
But in ode45 the vector returned by ODE function (EQM) and the initial conditions vector (qinit) must have the same number of elements.
What can I do if I need to solve my EQM having a q'' initial condition?
Thanks in advance!

Best Answer

You can't prescribe q'' since it is automatically given by
q'' = M^(-1)*(tau-g-C*q')
Best wishes
Torsten.