How does the time step affect the results of ODE solvers?

13 views (last 30 days)
Hello all,
I got question about ODE solvers. I have a rough understanding on how the calculations behind the solver are done and have read the documentation and other posts in other forums about them. I also have done a few tests, changing my time step and the solvers used (although I know my problem is a stiff one). Anyway, I have just started investigating these solutions and I was wondering: how does the time-step that I use affect the results. I am asking this because, in my understanding, the time step within the solver itself does not change. While, the initial conditions can affect a lot behavior of the solution.
I inherited a code from a peer and I am trying to optimize it. The ODE solver part of the code has the following structure, just to be clear on what I mean by "time step".
Tot_time = 2000; % s
interval = 0.05; % dt Integration time step
tot_it = Tot_time/interval;
while m <= tot_it
time0 = interval*(m-1);
timef = interval*m;
[tt, YY] = ode15s(@my_function, [time0 timef] ,dT, options);
dT = YY(end,:);
end
PS: this is just illustrative and it's just a piece of it to explain what I mean by time step, or dt.
I see different behaviors when I change he time step, but if the "internal" solver time-step does not change, how does the dt affect the solution? By affecting too much "initial" conditions? Just trying to understand this better.
Thank you!
:)

Accepted Answer

Bjorn Gustavsson
Bjorn Gustavsson on 18 Jan 2021
The way you call ode15s you simply chop up the time-intervall into sub-intervalls and integrate sub-intervall by sub-intervall. ode15s adaptively determines what time-steps it needs to take in order to reach some absolute and relative error-tolerances (within limits, if those break it typically throws an error to get out of numerical trouble, or aborts). Those time-steps you can control by adjusting the reltol and abstol field in the options-struct. The ode-integrating functions also determine what points in time is relevant for you, that's "typically" good. If you want more detailed help we'll need to see your my_function - that might help.
HTH
  3 Comments
Bjorn Gustavsson
Bjorn Gustavsson on 18 Jan 2021
The main reason for adapting dt is that it needs to "cleverly" guess the values of your YY variable and dYY/dt into the future based on the current values. This is done in incremental steps in time based on very clever schemes that are both (or some well thought-out compromise) computationally efficient, accurate and robust. Have a look at the description of the Runge-Kutta methods where you can see how those methods take steps along the gradients from the current point and neighboring points to get as good an estimate as possible to some dt forward. This is done using different schemes for the various ode-integrating functions, you'll have to check the methods in the documentation.
maitehar
maitehar on 18 Jan 2021
Great, I'll check the Runge-Kutta methods out and try to understand the solvers better. Thank you! :)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!