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

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!

 Accepted Answer

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

7 Comments

Thanks for your reply. Is there a way to solve Tau? knowing that it depends on q'' value? and in order to solve q'' a value for tau is needed.
If you want q''=0 at t=0, Tau must be equal to g at t=0.
Best wishes
Torsten.
Yes, in t(0), tau(0)=g and later, ode45 calculates a new value for q''. I need q'' value to calculate the new value for tau(1) -next iteration-. How can I do that?.
I mean, how can I save the calculated q'' value of one iteration, in order to use it for the next iteration and solve tau.
If you want to prescribe q'' as a function f(t), then why not just defining Tau as M*f(t)+C*q'+g ?
Best wishes
Torsten.
I'm sorry, I still don't understand how to do it. Can you please be more specific? How can I find f(t)... Perhaps and example with the code I put before? Thanks in advance
I think it's me who don't understand what you are trying to do.
I thought you wanted to prescribe q'' during the integration through the vector Tau, but now I'm confused because you ask "How can I find f(t)...". If you wanted to prescribe q'', you should know it in advance as a time dependent function f(t)...
Please try to explain again.
Best wishes
Torsten.
Torsten, it's true. I was formulating wrong my problem. It doesn't make sense what I was doing. Sorry to waste your time, but anyway it helped me to realize that I was doing something no-nonsense.

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Asked:

on 26 Apr 2017

Commented:

on 26 Apr 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!