what the time span do in ode45?

[time,Y] = ode45(f,tspan./tp,[sqrt(0.05);sqrt(0.05);0;0;0.1]);
in this, is it means that we differentiaite the y by "t/tp" ?

Answers (1)

Bruno Luong
Bruno Luong on 23 Jul 2022
No, it means exactly what in the doc says
"tspan — Interval of integration
vector
Interval of integration, specified as a vector. At a minimum, tspan must be a two-element vector [t0 tf] specifying the initial and final times.
To obtain solutions at specific times between t0 and tf, use a longer vector of the form [t0,t1,t2,...,tf]. The elements in tspan must be all increasing or all decreasing."

9 Comments

hey thanks.
can you explain me if I write this
tspan = [0 0.01]
what is the step size?
ode45 is variable step. It will take small steps when the function is changing rapidly, and it will take longer steps when the function is smoother. It does not have a fixed time step. This is fundamental to how ode45 works.
Note: if you pass in a vector of times, then ode45 will still continue to use variable time step, but each time it succeeds in reaching or exceeding one of the given times, it will interpolate what the value would be at the time.
The step size is adjusted automatically by ode45 depending on the smoothness/stiffness of your ode funtion.
It is nothiing to do with tspan, which is simply as thedc says the integration interval.
@Walter Roberson "it will interpolate what the value would be at the time."
In my mind, it actually arranged to have the subset of intermidiate times fall exatctly at the specify input tspan. So there is no interpolation.
When I traced the code a few years ago, when it was still all coded in MATLAB, all outputs were interpolated except for at event functions (and those are interpolated at the resolution of the minimum step size)
Hmm; if that is the case setup tspan is much less attractive to me. I can always interpolate afterward.
For piecewise rhs I would like finish at resart at the breakpoints, too bad that I have to write a for loop for that.
I think Mathworks should add a new behavior for the "terminal" output. Something like value 2 to signal discontinuity that does not require adjustment to the boundary conditions. Perhaps 3 could be similar but calls upon a function to adjust the boundaries.
For that matter perhaps combine those, in the sense of having an event boundary adjustment function, but defaulting it to empty, and then value 2 (or whatever) would indicate discontinuity that is to call the adjustment function if non-empty and then resume
@Bruno Luong: Walter is right. The output at the tspan points is interpolated. This is cheaper than interpolating afterwards, because it uses the information obtained be the function evaluations of the integrator. In addition this let the step size control determine the steps instead of increasing the number of function evaluations, which would increase the accumulated discretization and rounding errors also.
See the private help function ntrp45split.m and the reference: Mark W. Reichelt and Lawrence F. Shampine, 6-13-94 page 15:
Exploiting the freedom provided by a seven stage FSAL formula, Dormand and Prince [13] obtained a number of inexpensive interpolants. They have communicated to us another interpolant of order 4 that is of high quality and free. By free is meant that after a step is accepted, it is possible to construct an interpolant valid throughout the span of the step with no additional evaluations of F. Because solution components can change substantially in the course of a single step, the values computed at the end of each natural step may not provide adequate resolution for graphical display of the solution.
This means, that interpolating afterwards will be less accurate.
But all that arguments are only relevant for smooth and non piecewise rhs, for two reasons : (1) the hight order runge_kutta scheme is no longer accurate across the break points and (2) as the solution is not smooth any high order interpolation scheme is actually useless. (Well one reason you can argue).
If I want accurate solution I have to make my own stop and start on each interval.
That's fine but I like to be able to have a compact syntax, in the spirit of MATLAB.

Sign in to comment.

Tags

Asked:

on 23 Jul 2022

Commented:

on 23 Jul 2022

Community Treasure Hunt

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

Start Hunting!