confused with ode4 results

2 visualizaciones (últimos 30 días)
Dimitrios
Dimitrios el 17 de En. de 2015
I am using ode4 to simulate the motion of a body.I will make it simple:
dqdt = ode4(@obj.fun,obj.time,[2.5 0 0 0]')
where the dqdt(:,1) is the displacement and dqdt(:,3) the velocity.The same for index 2 and 4 for another direction.Inside the fun the code is similar to this:
function dqdt =fun(obj,t,q)
[Fx,Fy] = CalcForces(obj,t,q)
dqdt_temp = (obj.MassMatrix)\([FwindX;FwindY]-obj.Cmatrix*[q(1);q(2)]);
dqdt(1,1) = q(3);
dqdt(2,1) = q(4);
dqdt(3,1) = dqdt_temp(1);
dqdt(4,1) = dqdt_temp(2);
The results was not what i was expecting.So i start searching by debugging.So while I was running i also put another property to be saved(last line).Code became like this:
function dqdt =fun(obj,t,q)
[Fx,Fy] = CalcForces(obj,t,q)
dqdt_temp = (obj.MassMatrix)\([FwindX;FwindY]-obj.Cmatrix*[q(1);q(2)]);
dqdt(1,1) = q(3);
dqdt(2,1) = q(4);
dqdt(3,1) = dqdt_temp(1);
dqdt(4,1) = dqdt_temp(2);
indexT=round(t/obj.timestepPerThitaNode)+1;
obj.testDisplacement(indexT) = dqdt(1,1);
I run the simulation like this and in the end I plot dqdt(:,1) from the result of ode4 and also the obj.testDisplacement which was calculated inside the fun function .I thought that the results will be the same.The plots are following respectively(first dqdt(:,1) and second obj.testDisplacement):
Why the results in the second plot give so small displacement but in the end when the simulation finish the output is different?Is this how ode4 works or do i have something wrong?Its kinda strange but i cant find out why is this happening.Thanks in advance.I hope I was clear.

Respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by