Example code of Saving internal values from ode45 solver is needed.
5 views (last 30 days)
Show older comments
In the post, https://www.mathworks.com/matlabcentral/newsreader/view_thread/249317
Luke asked: 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 non-trivial 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 Matlab will try to integrate the force, right?
Sean mention " One is to write to a file, another is to use globals, and the third is to use the OutputFcn, which is relatively fast, but as I said, it's redundant because I already know the values I need."
Can you send me your code of how to use globals, and the third is to use the OutputFcn to do it?
He also mention you can do it in DAE form. I fail to do it. Can you send me your code of how to do it? Urgent! Many thanks.
In summary, can you give me an example of how to do it in
- globals
- OutputFcn
- dae
0 Comments
Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!