Filter löschen
Filter löschen

Why ODE solver tspan step size results with the same length are different?

5 Ansichten (letzte 30 Tage)
Dear all, i found the output z size in ODE solver (ex.ode45) are quite different even with the same tspan step size, inital time and final time.
So my question is: Why the results of tspan from ODE is different from the results without setting tspan?
Thanks in advance. Any help would be greatly appreciated.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 2 Nov. 2022
z = 149×1
...
0.7695
A span of 0.7695 in 149 steps is an average step size of 0.00516778523489933 not of 0.0019 . Your system might start out with 0.0019 but at some point that changes and the steps get roughly 2.7 times more dense.
All of the ode*() functions use adaptive steps. At any point, they have a current step size, and run a calculation based on that step size, and cross-check if the accuracy was good enough. If it was, then they "accept" the point, make it the current point, and increase the step size. If the accuracy was not good enough, then they reject the point, reduce the step size, and try again from the current location. In an area that is changing rapidly, a number of steps in a row can be rejected.
If you specified exactly two values in tspan, then each time a point is "accepted", if the Refine option is less than or equal to 1 then just the point itself is saved for output, but if Refine is greater than 1 then that many intermediate points are generated in the output. Default Refine is 4 -- so by default the first 4 points are going to have the same step size, as they are generated at equal times between the initial time and the first accepted point.
If you specified more than two values in tspan, then if an accepted step gets to or crosses one of the times in the vector, then values are interpolated for each of the times crossed between the previous output and the current location. Note I said "interpolated" -- the ode*() functions do not go back and ask the function for details at those times, and instead just use continuity and the fact that the step was considered to have acceptable accuracy, and simple interpolation is used. The ode*() functions are effectively doing a piecewise segmentation of the ode into places where a degree 4 or degree 5 equation is a "good enough" approximation -- and takes advantage of that in calculating intermediate positions.
  1 Kommentar
uki71319
uki71319 am 2 Nov. 2022
Wow, thank you very much for this detailed explanabntion, but i'm still a bit confused. In the case of tspan with only two elements, which step size i should use, 0.00516778523 or 0.0019?
SInce my task is to use the auto adaptive z step size further to determine another input size, and then put this as input in the odesolver to solve further....Do you have any ideas?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by