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

2 次查看(过去 30 天)
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

回答(2 个)

Yu Jiang
Yu Jiang 2014-8-14
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

Bo
Bo 2014-8-15
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.
Bo

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by