FUNCTION REFERENCE

ode45

Solve nonstiff differential equations, medium order (Dormand-Prince 5(4)).

Solve nonstiff differential equations, medium order (Dormand-Prince 5(4)).

Syntax

[t, y] = ode45(@(t,y) -y, tspan, y0)

Syntax

[t, y] = ode45(@f, tspan, y0, options, p1, p2, ...)

Syntax

[t, y, te, ye, ie] = ode45(@f, tspan, y0, odeset('Events', @eventFcn))

Syntax

sol = ode45(@f, tspan, y0)

Syntax

[t, y] = ode45('f', tspan, y0)

Syntax

[t, y] = ode45('f', tspan, y0, options)

Syntax

t = ode45('f', tspan, y0)

Integrates dy/dt = f(t, y) from tspan(1) to tspan(end). f can be an anonymous

handle, a named handle, or the text name of a function file (f.m or f.mr in

the Current Folder) or a local function. Anonymous handles capture workspace

variables when created. The function gets t and

the column y and returns a column of the same length. Arguments after options

are passed to f and the Events function. Use [] to pass extra arguments with

default options.

tspan = [t0 tf] returns the solver steps plus 3 points inside each step

(Refine 4). A longer tspan, increasing or decreasing, returns y at exactly

those times up to a terminal event, whose time and state complete the output.

A single number tf integrates from 0 to tf. Entries of tspan

must be finite.

Each row of y is the solution at the matching time in t.

Defaults: RelTol 1e-3, AbsTol 1e-6, MaxStep (tf - t0)/10. Change them with odeset.

If the tolerances cannot be met, a warning names the time and the result

so far is returned.

With a handle, one output is a solution structure for deval and odextend;

x is a row of solver steps and each column of y is a solution at that step.

See odeset for event callbacks and the orientation of the event outputs.

Example

[t, y] = ode45(@(t,y) -y, [0 1], 1); y(end)   % 0.3679

Example

[t, y] = ode45(@(t,y,k) -k*y, [0 1], 1, [], 2); y(end)   % approximately exp(-2)

Differences from MATLAB: the options Mass, NormControl and Stats are not supported

yet; they stop with an error. NonNegative, OutputFcn and OutputSel are supported. With a function name, one output is t, as in

MATLAB. With no output argument, the single-output result becomes ans instead

of plotting. The solution structure has solver, extdata, x, y, stats and

idata fields like MATLAB's; idata.f3d stores each step's stages as a 2-D

neq-by-(stages*N) matrix instead of a 3-D array. deval and odextend accept it.

NaN or Inf in tspan stops with an error; MATLAB does not reject NaN.

These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.