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
0 个评论
回答(2 个)
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!