MATLAB .m files that define differential equations
Paul Blanchard

In addition to Professor John Polking's MATLAB routines dfield5 and pplane5 to make pictures of slope fields, vector fields, and phase portraits, we also take advantage of his routines eul, rk2, and rk4 to compute numerical approximations to solutions. Euler's method from Chapter 1 and Chapter 2 is implemented in eul. The routines rk2 and rk4 implement Improved Euler and Runge-Kutta as described in Chapter 7.

MATLAB also has "professional" solvers that were written by experts in numerical approximation of solutions. These routines are called ode45, ode23, ode113, ode15s, ode23s, ode23t, and ode23tb. Euler's method is a good method to learn first because it is very close in concept to what a differential equation is, but serious numerical work should be done with one of MATLAB's built-in solvers. In most cases, I would start with ode45.

When you use any of these solvers, you need to make a separate file that contains the differential equation or system of differential equations. You can do this via MATLAB's editor/debugger, or you can use another editor if you prefer (emacs, for example). To access MATLAB's editor, use the edit command.

As discussed below, there is a slight difference between the file for a system of equations and the file for a single first-order equation, but there is one important rule that must be followed in both cases. The name of the file (without the .m) must be the same as the name of the command that defines the differential equation inside the file. For example, if the file is named bozo.m, then the first line of the file should be

function yprime = bozo(t,y)

Last revision: September 3, 2000