ode
Object that describes an initial value problem and holds its solver settings.
Category: Other public functions: funfun
Syntax
f = ode
Creates an empty problem to be filled in through its properties.
f = ode(Name=Value)
Creates the problem with properties given as name-value pairs, such as ODEFcn and InitialValue.
sol = solve(f, t0, tf)
Integrates from t0 to tf and returns an ODEResults object.
Description
The ode object is the newer interface to the ODE solvers: instead of one long call to ode45 with a pile of options, the problem and its settings are stored in one object that can be inspected, changed and solved again. solve(f, t0, tf) returns an object whose Time and Solution properties hold the time points and the states, with one column per time point.
The features that older code passed through odeset are now objects of their own: odeEvent for events, odeJacobian for the Jacobian and odeMassMatrix for a mass matrix.
Input arguments
ODEFcn- Function handle
@(t, y)giving the derivative of the state. InitialValue- State at the initial time.
InitialTime- Initial time, 0 by default.
Solver- A specific solver such as
'ode15s', or'auto'(default) to let the object choose. RelativeTolerance, AbsoluteTolerance- Error tolerances,
1e-3and1e-6by default. Jacobian, MassMatrix, EventDefinition- Optional
odeJacobian,odeMassMatrixandodeEventobjects.
Output arguments
f- An
odeobject. ItsSelectedSolverproperty tells which solver'auto'picked.
Example
Solve y' = -y
f = ode(ODEFcn=@(t, y) -y, InitialValue=1);
sol = solve(f, 0, 2);
fprintf('y(2) = %.3f\n', sol.Solution(end))
fprintf('exact %.3f\n', exp(-2))
y(2) = 0.135
exact 0.135