MATLAB Function Reference    
odefile

Define a differential equation problem for ordinary differential equation (ODE) solvers

Description

odefile is not a command or function. It is a help entry that describes how to create an M-file defining the system of equations to be solved. This definition is the first step in using any of MATLAB's ODE solvers. In MATLAB documentation, this M-file is referred to as an odefile, although you can give your M-file any name you like.

You can use the odefile M-file to define a system of differential equations in one of these forms

or

where:

The ODE file must accept the arguments t and y, although it does not have to use them. By default, the ODE file must return a column vector the same length as y.

All of the solvers of the ODE suite can solve , except ode23s, which can only solve problems with constant mass matrices. The ode15s and ode23t solvers can solve some differential-algebraic equations (DAEs) of the form .

Beyond defining a system of differential equations, you can specify an entire initial value problem (IVP) within the ODE M-file, eliminating the need to supply time and initial value vectors at the command line (see Examples).

To Use the ODE File Template

Notes

  1. The ODE file must accept t and y vectors from the ODE solvers and must return a column vector the same length as y. The optional input argument flag determines the type of output (mass matrix, Jacobian, etc.) returned by the ODE file.
  2. The solvers repeatedly call the ODE file to evaluate the system of differential equations at various times. This is required information - you must define the ODE system to be solved.
  3. The switch statement determines the type of output required, so that the ODE file can pass the appropriate information to the solver. (See notes 4 - 9.)
  4. In the default initial conditions ('init') case, the ODE file returns basic information (time span, initial conditions, options) to the solver. If you omit this case, you must supply all the basic information on the command line.
  5. In the 'jacobian' case, the ODE file returns a Jacobian matrix to the solver. You need only provide this case when you want to improve the performance of the stiff solvers ode15s, ode23s, ode23t, and ode23tb.
  6. In the 'jpattern' case, the ODE file returns the Jacobian sparsity pattern matrix to the solver. You need to provide this case only when you want to generate sparse Jacobian matrices numerically for a stiff solver.
  7. In the 'mass' case, the ODE file returns a mass matrix to the solver. You need to provide this case only when you want to solve a system in the form .
  8. In the 'events' case, the ODE file returns to the solver the values that it needs to perform event location. When the Events property is set to on, the ODE solvers examine any elements of the event vector for transitions to, from, or through zero. If the corresponding element of the logical isterminal vector is set to 1, integration will halt when a zero-crossing is detected. The elements of the direction vector are -1, 1, or 0, specifying that the corresponding event must be decreasing, increasing, or that any crossing is to be detected.
  9. An unrecognized flag generates an error.

Examples

The van der Pol equation,

, is equivalent to a system of coupled first-order differential equations.

The M-file

defines this system of equations (with µ = 1).

To solve the van der Pol system on the time interval [0 20] with initial values (at time 0) of y(1) = 2 and y(2) = 0, use

To specify the entire initial value problem (IVP) within the M-file, rewrite vdp1 as follows.

You can now solve the IVP without entering any arguments from the command line.

In this example the ode23 function looks to the vdp1 M-file to supply the missing arguments. Note that, once you've called odeset to define options, the calling syntax

also works, and that any options supplied via the command line override corresponding options specified in the M-file (see odeset).

See Also

The MATLAB Version 5 help entries for the ODE solvers and their associated functions: ode23, ode45, ode113, ode15s, ode23s, ode23t, ode23tb, odeget, odeset

Type at the MATLAB command line: more on, type function, more off. The Version 5 help follows the Version 6 help.


 ode45, ode23, ode113, ode15s, ode23s, ode23t, ode23tb odeget