Solving ODE Problems
This section uses the van der Pol equation
to describe the process for solving initial value ODE problems using the ODE solvers.
|Note See ODE Solver Basic Syntax for more information.|
Example: Solving an IVP ODE (van der Pol Equation, Nonstiff)
This example explains and illustrates the steps you need to solve an initial value ODE problem.
ymust be the function's first two arguments, the function does not need to use them. The output
dydt, a column vector, is the derivative of
The code below represents the van der Pol system in the function,
vdp1 function assumes that . and become elements
y(2) of a two-element vector.
Note that, although
vdp1 must accept the arguments
y, it does not use
t in its computations.
ode45on time interval
[0 20]with initial values
y(1) = 2and
y(2) = 0.
This example uses
@ to pass
vdp1 as a function handle to
ode45. The resulting output is a column vector of time points
t and a solution array
y. Each row in
y corresponds to a time returned in the corresponding row of
t. The first column of
y corresponds to , and the second column to .
See the |
plotcommand to view the solver output.
OutputFcnafter each successful time step. Use
OutputFcnto the desired function. See OutputFcn for more information.
Passing Additional Parameters to an ODE Function
The solver passes any input parameters that follow the
options argument to the ODE function and any function you specify in
options. For example:
muparameter, instead of specifying a value for
muexplicitly in the code.
muto the function
vdp1by specifying it after the
optionsargument in the call to the solver. This example uses
options = as a placeholder.
vdpode code for a complete example based on these functions.
Example: The van der Pol Equation, µ = 1000 (Stiff)
This example presents a stiff problem. For a stiff problem, solutions can change on a time scale that is very short compared to the interval of integration, but the solution of interest changes on a much longer time scale. Methods not designed for stiff problems are ineffective on intervals where the solution changes slowly because they use time steps small enough to resolve the fastest possible change.
When is increased to 1000, the solution to the van der Pol equation changes dramatically and exhibits oscillation on a much longer time scale. Approximating the solution of the initial value problem becomes a more difficult task. Because this particular problem is stiff, a solver intended for nonstiff problems, such as
ode45, is too inefficient to be practical. A solver such as
ode15s is intended for such stiff problems.
vdp1000 function evaluates the van der Pol system from the previous example, but with = 1000.
This example hardcodes in the ODE function. The |
Now use the
ode15s function to solve the problem with the initial condition vector of
[2; 0], but a time interval of
[0 3000]. For scaling purposes, plot just the first component of
|Note For detailed instructions for solving an initial value ODE problem, see Example: Solving an IVP ODE (van der Pol Equation, Nonstiff).|
Evaluating the Solution at Specific Points
The numerical methods implemented in the ODE solvers produce a continuous solution over the interval of integration . You can evaluate the approximate solution, , at any point in using the function
deval and the structure
sol returned by the solver.
The ODE solvers return the structure
sol when called with a single output argument.
deval function is vectorized. For a vector
ith column of
Sxint approximates the solution .
|Initial Value Problem Solvers||Changing ODE Integration Properties|