MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi
Learn moreOpportunities for recent engineering grads.
Apply TodayMATLAB Central > MATLAB Newsreader > saving internal values from ode45 solver 

Subject: saving internal values from ode45 solver From: Luke Date: 17 Apr, 2009 19:07:01 Message: 1 of 8 
Okay, I have a problem I can't figure out. I'm solving a set of ODE's with ODE 45 for a system of springs/masses. The force on each mass varies at each time step based on the position of the masses in a nontrivial way. The function called by ode45 first calculates the forces at each time step, then solves for positions. The solution is fine, but how can I store/access the force values for each time step? I've tried using a global variable, but the resultant vector is too long (683 force values, only 430 positions in the output). I'm guessing this has to do with the ode solver refining the time steps and throwing away solutions when it does this, whereas the global force variable saves all the solutions. But how can I get just the forces at each of the time steps output at the end of the ode45 routine? I don't think it's as simple as adding the force to the dy output vector, since then 
Subject: saving internal values from ode45 solver From: KurtCav Date: 29 Apr, 2009 08:01:09 Message: 2 of 8 
I've been trying to solve this same problem. I have a RungeKutta 
Subject: saving internal values from ode45 solver From: Sean Torrez Date: 10 Jun, 2009 15:06:02 Message: 3 of 8 
I have also been working on this problem. Has anyone found a good way to do it? Seems like they ought to just add this functionality to the ODE solvers, since it's pretty common to want to get nonderivative information (or the values of the derivatives!) from the internals of the ODE routines. I think there may be a way to do it with the 'OutputFcn' option, but in my case, that will me recomputing several values from scratch which are already available to me from the original derivative function. 
Subject: saving internal values from ode45 solver From: Sean Torrez Date: 11 Jun, 2009 13:28:03 Message: 4 of 8 
Figured it out. Treat the problem as a differentialalgebraic equation. There is some stuff on this in the help (not enough, as usual), enough to figure it out. 
Subject: saving internal values from ode45 solver From: Richard Crozier Date: 11 Jan, 2010 11:19:03 Message: 5 of 8 
"Sean Torrez" <eltorrisimo@gmail.com> wrote in message <h0r0p3$qc0$1@fred.mathworks.com>... 
Subject: saving internal values from ode45 solver From: Richard Crozier Date: 11 Jan, 2010 13:07:04 Message: 6 of 8 
"Richard Crozier" <r.crozier@ed.ac.uk> wrote in message <hif1f7$ns2$1@fred.mathworks.com>... 
Subject: saving internal values from ode45 solver From: Andres Mauricio Gonzalez Date: 14 Mar, 2012 16:22:12 Message: 7 of 8 
This might be inelegant, but works: 
Subject: saving internal values from ode45 solver From: Richard Crozier Date: 15 Mar, 2012 09:03:24 Message: 8 of 8 
"Andres Mauricio Gonzalez" <biomedicoandres@gmail.com> wrote in message <jjqgjk$mf$1@newscl01ah.mathworks.com>... 
A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.
Anyone can tag a thread. Tags are public and visible to everyone.