Filter löschen
Filter löschen

Why is ODE45 using so many intervals?

1 Ansicht (letzte 30 Tage)
Thomas Veith
Thomas Veith am 17 Jun. 2019
Beantwortet: Jan am 17 Jun. 2019
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);

Akzeptierte Antwort

Star Strider
Star Strider am 17 Jun. 2019
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 Kommentare
Star Strider
Star Strider am 17 Jun. 2019
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 am 17 Jun. 2019
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Jan
Jan am 17 Jun. 2019
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?

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by