how to save only part of the solution when calling ODE routines

6 views (last 30 days)
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!

Answers (2)

Yu Jiang
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);
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

Bo on 15 Aug 2014
Thanks! But that is not what I asked. Sorry for the confusion, let me give an example.
Say I would like to solve a ODE system that has two variables:
dY1/dt = something 1 dY2/dt = something 2
Now I can solve the problem with matlab's ode suite. However, I am only interested in getting Y1 not Y2. Is there a way only output Y1 not Y2?
My problem is that these variables Y1 and Y2 are all 3 dimensional matrices. So they need a lot of memory to cache. What makes it even worse is that There are 36 equations need to be solved simultaneously. I am only interested in the first variable, all other variables do not need to be reported and accumulated during solving the problem. Currently all the variables are in the output which makes the output variable very clumky and slows down the computer.
Let me know if this answers your question.


Community Treasure Hunt

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

Start Hunting!

Translated by