Note: This page has been translated by MathWorks. Please click here

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Solve nonstiff differential equations — medium order method

```
[t,y] =
ode45(odefun,tspan,y0)
```

```
[t,y] =
ode45(odefun,tspan,y0,options)
```

```
[t,y,te,ye,ie]
= ode45(odefun,tspan,y0,options)
```

`sol = ode45(___)`

`[`

,
where `t`

,`y`

] =
ode45(`odefun`

,`tspan`

,`y0`

)`tspan = [t0 tf]`

, integrates the system of
differential equations $$y\text{'}=f\left(t,y\right)$$ from `t0`

to `tf`

with
initial conditions `y0`

. Each row in the solution
array `y`

corresponds to a value returned in column
vector `t`

.

All MATLAB^{®} ODE solvers can solve systems of equations of
the form $$y\text{'}=f\left(t,y\right)$$,
or problems that involve a mass matrix, $$M\left(t,y\right)y\text{'}=f\left(t,y\right)$$.
The solvers all use similar syntaxes. The `ode23s`

solver
only can solve problems with a mass matrix if the mass matrix is constant. `ode15s`

and `ode23t`

can
solve problems with a mass matrix that is singular, known as differential-algebraic
equations (DAEs). Specify the mass matrix using the `Mass`

option
of `odeset`

.

`ode45`

is a versatile ODE solver and is the
first solver you should try for most problems. However, if the problem
is stiff or requires high accuracy, then there are other ODE solvers
that might be better suited to the problem. See Choose an ODE Solver for
more information.

`[`

additionally
finds where functions of (`t`

,`y`

,`te`

,`ye`

,`ie`

]
= ode45(`odefun`

,`tspan`

,`y0`

,`options`

)*t*,*y*),
called event functions, are zero. In the output, `te`

is
the time of the event, `ye`

is the solution at the
time of the event, and `ie`

is the index of the triggered
event.

For each event function, specify whether the integration is
to terminate at a zero and whether the direction of the zero crossing
matters. Do this by setting the `'Events'`

property
to a function, such as `myEventFcn`

or `@myEventFcn`

,
and creating a corresponding function: [`value`

,`isterminal`

,`direction`

]
= `myEventFcn`

(`t`

,`y`

).
For more information, see ODE Event Location.

`ode45`

is based on an explicit Runge-Kutta
(4,5) formula, the Dormand-Prince pair. It is a single-step solver
– in computing `y(t`

,
it needs only the solution at the immediately preceding time point, _{n})`y(t`

[1], [2]._{n-1})

[1] Dormand, J. R. and P. J. Prince, “A
family of embedded Runge-Kutta formulae,” *J. Comp.
Appl. Math.*, Vol. 6, 1980, pp. 19–26.

[2] Shampine, L. F. and M. W. Reichelt, “The
MATLAB ODE Suite,” *SIAM Journal on Scientific
Computing*, Vol. 18, 1997, pp. 1–22.

Was this topic helpful?