ode - Saving derivative values in ode45 in Matlab -


i'm simulating equations of motion (somewhat odd) system mass-springs , double pendulum, have mass matrix , function f(x), , call ode45 solve

m*x' = f(x,t); 

i have 5 state variables, q= [ qdot, phi, phidot, r, rdot]'; (removed q because nothing depends on it, qdot current.) now, calculate forces, save calculated values of rdotdot, ode45 calculates each integration step, ode45 doesn't give back. i've searched around bit, 2 solutions i've found a) turn 3rd order problem , add phidotdot , rdotdot state vector. avoid as possible, it's non-linear , makes matters lot worse , blows computation time.

b) augment state directly calculate function, described here. however, in example says make add line of zeros in mass matrix. makes sense, since otherwise integrate derivative , not evaluate @ 1 point, on other hand makes mass matrix singular. doesn't seem work me...

this seems such basic thing (to want derivative values of state vector), there quite obvious i'm not thinking of? (or not obvious ok too....)

oh, , global variables not great because ode45 calls f() function several time while refining it's step, sizes of global variable , returned state vector q don't match @ all.

in case needs it, here's code:

%(initialization of parameters above line)    options = odeset('mass',@massmatrix);    [t,q] = ode45(@f, tspan,q0,options);  function dqdt = f(t,q,p)     % q = [qdot phi phidot r rdot]';      dqdt = zeros(size(q));      dqdt(1) = -r/l*q(1) - kb/l*q(3) +vs/l;     dqdt(2) = q(3);     dqdt(3) = kt*q(1) + mp*sin(q(2))*lp*g;     dqdt(4) = q(5);     dqdt(5) = mp*lp*cos(q(2))*q(3)^2 - ks*q(4) - (mb+mp)*g; end  function m = massmatrix(~,q)     m = [         1 0 0 0 0;         0 1 0 0 0;         0 0 mp*lp^2 0 -mp*lp*sin(q(2));         0 0 0 1 0;         0 0 mp*lp*sin(q(2)) 0 (mb+mp)         ]; end 

the easiest solution re-run function on each of values returned ode45.

the hard solution try log dotdots other place (a pre-allocated matrix or external file). problem might end unwanted data points if ode45 secretly evaluations in weird places.


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -