Why ODE solver tspan step size results with the same length are different?
17 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Walter Roberson
2022-11-2
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!