Why is ODE45 using so many intervals?

8 ビュー (過去 30 日間)
Thomas Veith
Thomas Veith 2019 年 6 月 17 日
回答済み: Jan 2019 年 6 月 17 日
Hi all,
I'm using the code below to solve an ODE. It's not problematic per se, but I'm just wondering if there is a way to force it to use less intervals? As it is written below, I get 22,237 entries for both x and y in my sol structure.
options=odeset('RelTol', 1e-8, 'AbsTol', 1e-8);
tspan=[0 50];
ODE = @(t,x,gamma,psi,beta) [-gamma*x(1) + psi*x(1); beta*x(2) - x(1)*x(2)];
sol = ode45(@(t,x) ODE(t,x,0.4116,0.6026,0.7505), tspan, [1 29], options);

採用された回答

Star Strider
Star Strider 2019 年 6 月 17 日
It will use as many intervals as it needs to.
If you want it to output fewer intervals, create ‘tspan’ as a vector of more than two elements, for example:
tspan = linspace(0, 50, 25);
will result in the result having 25 values for the time vector and a (25xN) matrix for the integrated solution.
  3 件のコメント
Star Strider
Star Strider 2019 年 6 月 17 日
My pleasure.
I always just do this:
tspan = linspace(0, 50, 50);
[t,y] = ode45(@(t,x) ODE(t,x,0.4116,0.6026,0.7505), tspan, [1 29], options);
I have no idea why it fails to follow the elements of tspan when using the structure output, however, I was able to reproduce that behaviour. If you want to force the integrator to output its results using the elements of tspan, use the convention I use here, rather than the structure output.
Jan
Jan 2019 年 6 月 17 日
If the output of ode45 is caught as a struct, a vector valued tspan is ignored. I still consider this as a bug, reported it some years ago, but MathWorks thinks, this is the wanted behaviour. You need just to change one line in ode45.m to get the expected time steps in the output.

サインインしてコメントする。

その他の回答 (1 件)

Jan
Jan 2019 年 6 月 17 日
Do you want to reduce the number of evaluated steps to reduce the processing time, or is it enough to reduce the size of teh output, because you need less points?
For the later you can either use interp1 or a faster metod from the FileExchange, or use the two outputs [t,y] instead of the struct (see my comment above).
To get less evaluated steps, either increase the tolerances, or use another integrator. Did you check if the problem is stiff?

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by