how to save only part of the solution when calling ODE routines
2 views (last 30 days)
Show older comments
Hi,
I am solving a fairly large system of equations with ode113 but I only need part of the solution to be saved, otherwise a lot of memory is wasted. It seem that outputfcn can do such thing, but I cannot find a solid example. Could anyone help me on this topic? Thanks!
Bo
0 Comments
Answers (2)
Yu Jiang
on 14 Aug 2014
Hi Bo
From what I understand, you would like to save only a portion of the results obtained from ODE113.
A simple way to do it is to specify a series of time points at which you would like to save the answer, instead of only providing a time interval.
For example, let us define such a system
function dx = foo(t,x)
dx = sin(100*x);
end
To solve the system on the interval [0,1000], one can use the following code
x0 = 1;
[t,y] = ode113(@foo, [0 1000], x0);
From what I tested, y will be a matrix with 59857 rows.
But if you do the following
[t,y] = ode113(@foo, [0:1:1000], x0)
Then, y will only have 1001 rows.
However, in either way the executing time of ode113 will be the same, otherwise the simulation accuracy will be affected.
-Yu Jiang
0 Comments
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!