Problem with matrix differential equation resolve in Matlab with ode45

1 visualización (últimos 30 días)
Hi,
I would like to solve this linearized matrix differential equation:
My program has no errors but the result it gives seems inconsistent. Here is my program:
vt= linspace(0,10,500);
v=0.5*vt;
Q0=[0 0;0 0];
tspan=[0 10];
M=[80.8 2.32;2.32 0.28];
K0=[-80.95 -2.6;-2.6 -0.8];
K2=[0 76.6 ; 0 2.65];
C1=[0 33.87; -0.86 1.68];
q=ones(2,2);
[tSol,QSol]=ode45(@(tSol,QSol) myodefun(tSol,q,vt,v,M,K0,K2,C1,f),tspan,Q0);
function dQdt=myodefun(t,q,vt,v,M,K0,K2,C1)
v=interp1(vt,v,t);
Q1=q(:,1);
Q2=q(:,2);
dQ1dt=M*Q2;
dQ2dt=-v*C1*Q2-(9.81*K0+v*v*K2)*Q1;
dQdt=[dQ1dt;dQ2dt];
end
Do you see anything I did wrong to solve this equation?

Respuesta aceptada

James Tursa
James Tursa el 26 de Abr. de 2021
Editada: James Tursa el 26 de Abr. de 2021
Normally I would have expected ode45( ) to pass q as a 4x1 column vector. Also, I don't see anything in your code solving for qdotdot that would involve backslash or the inverse of M. E.g., something like this for a derivative function:
% assume q is passed in as 4x1 column vector
function dQdt=myodefun(t,q,vt,v,M,K0,K2,C1)
v=interp1(vt,v,t);
qdot = q(3:4);
q = q(1:2);
qdotdot = M \ (-v*C1*qdot - (9.81*K0+v*v*K2)*q);
dQdt=[qdot;qdotdot];
end
And what is f? I don't see that defined. And I don't see it being used in myodefun.
  2 comentarios
Antoine W
Antoine W el 26 de Abr. de 2021
Thanks for your answer, f is just a parameter I forgot to remove. By just adding a reshape on q and qdot, your program works. However when outputting to QSol in what orders is it returned between phidt deltadt phi and delta?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by