How do I force ode45 to take steps of exactly 0.01 on the T axis?

前端 未结 6 1899
再見小時候
再見小時候 2021-01-05 14:44

I\'m using Matlab to solve a differential equation. I want to force ode45 to take constant steps, so it always increments 0.01 on the T axis while solving the equation. How

6条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-05 15:02

    Based on the documentation it doesn't appear that you can control the size of the steps taken internally by ode45 when solving the equation, but you can control the time points at which the output is generated. You can do this as indicated in your commented-out line:

    tspan = to:0.01:tf;  % Obtain solution at specific times
    [T, Y] = ode45(name, tspan, init, options);
    

    With respect to the accuracy of solutions when fixed step sizes are used, refer to this excerpt from the above link:

    If tspan has more than two elements [t0,t1,t2,...,tf], then the solver returns the solution evaluated at the given points. However, the solver does not step precisely to each point specified in tspan. Instead, the solver uses its own internal steps to compute the solution, then evaluates the solution at the requested points in tspan. 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.

    So, even when you specify that you want the solution at specific time points in the output, the solvers are still internally taking a number of adaptive steps between the time points that you indicate, coming close to the values at those fixed time points.

提交回复
热议问题