Post by Alyson TurriI would like to determine the time step size that Matlab uses at each
time tn (delta t = t(n) - t(n-1)). Is there a way to do this using
the ode45 solver? I know that there are some fixed step solvers on
the Matlab website but I would prefer to use the more robust ode45.
I would like to perform a calculation using this delta t time step
size at each time step t(n). Thanks in advance.
This question is REALLY old, but I've come across it and it seems that the answer to what you wanted was on the actual ode45 function itself. The documentation says that if you provide the [t0 tf] vector, than the resulting [t] output will be in terms of each integration cycle as performed by the function. On the other hand, if you provide a vector with all the steps [t0,t1,t2,...,tf], then the output [t] will be in terms of the steps provided, which are an approximation of the integration cycle, although the system still does the calculations with it's own integration steps. The approximation to the steps are still accurate.
From the documentation (https://www.mathworks.com/help/matlab/ref/ode45.html#inputarg_tspan):
The solver imposes the initial conditions, y0, at tspan(1), then integrates from tspan(1) to tspan(end):
If tspan has two elements, [t0 tf], then the solver returns the solution evaluated at each internal integration step within the interval.
If tspan contains more than two elements [t0,t1,t2,...,tf], then the solver returns the solution evaluated at the given points. This does not affect the internal steps that the solver uses to traverse from tspan(1) to tspan(end). Thus, the solver does not necessarily step precisely to each point specified in tspan. However, the solutions produced at the specified points are of the same order of accuracy as the solutions computed at each internal step.
Specifying several intermediate points has little effect on the efficiency of computation, but for large systems it can affect memory management.
The solution obtained by the solver might be different depending on whether you specify tspan as a two-element vector or as a vector with intermediate points. If tspan contains several intermediate points, then they give an indication of the scale for the problem, which can affect the size of the initial step taken by the solver.
Example: [1 10]
Example: [1 3 5 7 9 10]