필터 지우기
필터 지우기

Why is ODE45 using so many intervals?

조회 수: 1 (최근 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 CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by