# Is there a fixed-step Ordinary Differential Equation (ODE) solver in MATLAB 8.0 (R2012b)?

335 views (last 30 days)
All the current ODE solvers are variable-step. I would like to use a fixed-step solver.

MathWorks Support Team on 29 Aug 2019
Edited: MathWorks Support Team on 29 Aug 2019
The ability to use a fixed-step solver is not built into MATLAB 8.0 (R2012b).
The ordinary differential equation solver functions provided with MATLAB employ a variety of variable-step methods. ODE23 is based on the Runge Kutta (2,3)integration method, and ODE45 is based on the Runge Kutta (4,5) integration method. ODE113 is a variable-order Adams-Bashforth-Moulton PECE solver. For a complete listing of the various solvers and their methods, see the documentation.
The MATLAB ODE solvers utilize these methods by taking a step, estimating the error at this step, checking to see if the value is greater than or less than the tolerance, and altering the step size accordingly. These integration methods do not lend themselves to a fixed step size. Using an algorithm that uses a fixed step size is dangerous since you can miss points where your signal frequency is greater than the solver frequency. Using a variable step ensures that a large step size is used for low frequencies and a small step size is used for high frequencies. The ODE solvers within MATLAB are optimized for a variable step, run faster with a variable step size, and clearly the results are more accurate.
There are now fixed time step solvers available:
ODE1 - A first-order Euler method
ODE2 - A second-order Euler method
ODE3 - A third-order Runge-Kutta method
ODE4 - A fourth-order Runge-Kutta method
ODE5 - A fifth-order Runge-Kutta method
ODETest
These are included in the attached zip file. After saving the files into a folder located on the MATLAB path, these solvers can be used with the following syntax:
y = ode4(odefun,tspan,y0);
The integration proceeds by steps, taken to the values specified in tspan. The time values must be in order, either increasing or decreasing. Note that the step size (the distance between consecutive elements of tspan) does not have to be uniform. If the step size is uniform, you might want to use LINSPACE.
For example,
tspan = linspace(t0,tf,nsteps); % t0 = 0; tf = 10, nsteps = 100;
Since these files do not ship with MATLAB, these solvers are not officially supported.

K on 5 May 2017
Why the computational efficiency of this fixed step integration algorithm is much lower than 'ode45' to a same problem? The subroutine 'ode5' needs 0.1 seconds to complete an integration, however the 'ode45' need only 0.02 seconds. Does anyone know the reason?
Jan on 6 Aug 2017
@K: Of course the dynamic step size control of ODE45 can increase the step size and reduce the number of function evaluations. A solver with a fixed step size cannot operate on the optimal point between the accumulated rounding errors and the local discretization error. Therefore the fixed step size solver ODE5 is expected to be less accurate then ODE45. And if you try to increase the accuracy by reducing the step size, the computing time will increase.
Use fixed step solvers only to avoid the need to restart the integration at discontinuities and if a rough solution is sufficient.
Mounir guesbaya on 7 Apr 2019
Thank you so much MathWorks Support Team for everything, I appreciate your help, really meant a lot to me.

Deepraj on 27 Jan 2014
Why does the ODE is being executed twice at t0 ? This is causing problem in my code. I found this by displaying 't' in the file where differential equations are written.

Shivam on 20 Mar 2014
Hi Deepraj, I got around the problem by just taking the second row at that particular instance. Infact the ode4 method executes twice at each fixed time step, so each time I get the 2nd row.

R14SP3

### Community Treasure Hunt

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

Start Hunting!