ode45
Solve nonstiff differential equations — medium order method
Syntax
Description
[
, wheret
,y
] = ode45(odefun
,tspan
,y0
)tspan = [t0 tf]
, integrates the system of differential equations
fromt0
totf
with initial conditionsy0
. Each row in the solution arrayy
corresponds to a value returned in column vectort
.
All MATLAB®ODE solvers can solve systems of equations of the form
, or problems that involve a mass matrix,
. The solvers all use similar syntaxes. Theode23s
solver only can solve problems with a mass matrix if the mass matrix is constant.ode15s
andode23t
can solve problems with a mass matrix that is singular, known as differential-algebraic equations (DAEs). Specify the mass matrix using theMass
option ofodeset
.
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. SeeChoose an ODE Solverfor more information.
[
additionally finds where functions of(t,y), called event functions, are zero. In the output,t
,y
,te
,ye
,ie
] = ode45(odefun
,tspan
,y0
,options
)te
is the time of the event,ye
is the solution at the time of the event, andie
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 asmyEventFcn
or@myEventFcn
, and creating a corresponding function: [value
,isterminal
,direction
] =myEventFcn
(t
,y
). For more information, seeODE Event Location.
Examples
Input Arguments
Output Arguments
Algorithms
ode45
is based on an explicit Runge-Kutta (4,5) formula, the Dormand-Prince pair. It is a single-step solver – in computingy(tn)
, it needs only the solution at the immediately preceding time point,y(tn-1)
[1],[2].
References
[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.
Extended Capabilities
Version History
Introduced before R2006a