confused with ode4 results

5 Ansichten (letzte 30 Tage)
Dimitrios
Dimitrios am 17 Jan. 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.

Antworten (0)

Kategorien

Mehr zu Particle & Nuclear Physics finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by