From the series: Solving ODEs in MATLAB
Cleve Moler, MathWorks
The MATLAB documentation provides two charts summarizing the features of each of the seven functions in the MATLAB ODE suite.
We can get to documentation for the MATLAB ODE Suite by entering this command at the MATLAB prompt-- doc ode45. This will bring us to an extensive documentation for MATLAB ode45 that includes among other things this chart that compares MATLAB ODE solvers. There are seven of them and this compares their various attributes. As we've said before, MATLAB ode45 is the workhorse. It's a nonstiff solver with medium accuracy that is the first one you should try, and we use it most of the time.
I have a soft heart in my heart for MATLAB ode23. It's a nonstiff solver with low accuracy, but its accuracy that's appropriate for graphics work because the step size it chooses is appropriate for most graphics work. MATLAB ode113 we haven't talked about it yet, there could be a comma between the 1 and the 13 here because this is a variable order method where the order varies all the way from 1 to 13. It's a multi-step method that saves history.
If, you know about these things, it's an Adams-Moulton method. I associate this with worked done at Jet Propulsion Laboratory years ago for computing orbits of planets and satellites, which of course are very smooth and go on for years. It can have very high accuracy requirements.
Then there are the stiff solvers. There are four of them-- 15s, 23s, and the twins, the trapezoid rules. 15s is the primary stiff solver, low to medium accuracy. If you find ode45 is slow, taking lots of steps-- indication that the problem is stiff-- try 15s.
23s can be as a low order method, low accuracy, and used at crude error tolerances. We haven't talked about mass matrices. This is where there's a matrix in front of the derivative term, and this can be used with constant mass matrices. And then the two routines with T's in their name are based on the trapezoidal rule, and they're for use with problems without any numerical damping. You can see the documentation for more details on the trapezoid methods.
That's the MATLAB ODE Suite seven solvers, three for nonstiff problems and four for stiff problems. You may well get through with never using anything but ode45 may well serve all your needs.
There's a second chart in the documentation that summarizes all the options that are available through the ODE Set function. We've briefly mentioned the tolerances, RelTol and AbsTol-- the output function-- these are available in all seven of the solvers.
There are various other functions-- various other options-- available for more specialized work, including event handling, providing a Jacobian to the stiff solvers so they don't have to work so hard taking numerical differences, options associated with the mass matrices, providing a limit on the step size. These are all our options that can be specified through ode Set for more specialized work with the ODE solvers.
1: Euler, ODE1 ODE1 implements Euler's method. It provides an introduction to numerical methods for ODEs and to the MATLAB suite of ODE solvers. Exponential growth and compound interest are used as examples.
2: Midpoint Method, ODE2 ODE2 implements a midpoint method with two function evaluations per step. This method is twice as accurate as Euler's method. A nonlinear equation defining the sine function provides an example. An exercise involves implementing a trapezoid method.
3: Classical Runge-Kutta, ODE4 ODE4 implements the classic Runge-Kutta method, the most widely used numerical method for ODEs over the past 100 years. Its major shortcoming is the lack of an error estimate. A simple model of the growth of a flame is an example that is used.
4: Order, Naming Conventions The digits in the name of a MATLAB ODE solver reflect its order and resulting accuracy. A method is said to have order p if cutting the step size in half reduces the error in one step by a factor of two to the power p+1.
5: Estimating Error, ODE23 ODE23 compares 2nd and 3rd order methods to automatically choose the step size and maintain accuracy. It is the simplest MATLAB solver that has automatic error estimate and continuous interpolant. ODE23 is suitable for coarse accuracy requirements.
6: ODE45 ODE45 is usually the function of choice among the ODE solvers. It compares 4th and 5th order methods to estimate error and determine step size.
7: Stiffness, ODE23s, ODE15s A problem is said to be stiff if the solution being sought varies slowly, but there are nearby solutions that vary rapidly, so the numerical method must take small steps to obtain satisfactory results. The flame model demonstrates stiffness.
8: Systems of Equations An ODE involving higher order derivatives is rewritten as a vector system involving only first order derivatives. The classic Van der Pol nonlinear oscillator is provided as an example. The VdP equation becomes stiff as the parameter is increased.
9: The MATLAB ODE Suite The MATLAB documentation provides two charts summarizing the features of each of the seven functions in the MATLAB ODE suite.
10: Tumbling Box Throw a rectangular box with sides of three different lengths into the air. You can get the box to tumble stably about its longest axis or its shortest axis. But if you try to make it tumble about it middle axis, you will find the motion is unstable.
11: Predator-Prey Equations The classic Lotka-Volterra model of predator-prey competition is a nonlinear system of two equations, where one species grows exponentially and the other decays exponentially in the absence of the other. The program "predprey" studies this model.
12: Lorenz Attractor and Chaos The Lorenz chaotic attractor was discovered by Edward Lorenz in 1963 when he was investigating a simplified model of atmospheric convection. It is a nonlinear system of three differential equations. The program "lorenzgui" studies this model.