MATLAB Function Reference
  Go to function:
    Search    Help Desk 
odefile    Examples   See Also

Define a differential equation problem for 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 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:


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.

Only the stiff solvers ode15s, ode23t, and ode23tb can solve . ode15s, ode23s, ode23t, and ode23tb can solve equations 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 on page 2-517).

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 steps 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 wish to improve the performance of the stiff solvers ode15s and ode23s.
   6.
In the 'jpattern' case, the ODE file returns the Jacobian sparsity pattern matrix to the solver. You need 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 provide this case only when you want to solve a system in either of the forms or .
   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 1, 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. See Using MATLAB and also the examples ballode and orbitode.
   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).

Some example ODE files we have provided include b5ode,brussode,vdpode,orbitode, and rigidode. Use type filename from the MATLAB command line to see the coding for a specific ODE file.

See Also

The Applying MATLAB and the reference entries for the ODE solvers and their associated functions:

ode23, ode45, ode113, ode15s, ode23s, odeget, odeset



[ Previous | Help Desk | Next ]