odeFunction
Converts symbolic expressions into a numeric function handle for ODE solvers.
Category: Mathematics > Equation Solving
Syntax
f = odeFunction(expr, vars)
Returns a handle f(t, Y) that evaluates the vector expr for the state Y.
Description
odeFunction does for ODEs what matlabFunction does for plain expressions: it generates a numeric function in which the state variables become the entries of Y. Parameters that are symbolic variables become extra arguments after Y.
Input arguments
expr- Vector of symbolic expressions: the right-hand side of
y' = expr. vars- Vector of symbolic functions that make up the state, such as
[x(t); y(t)].
Output arguments
f- Function handle with the signature
f(t, Y)expected byode45, returning a column vector.
Example
Harmonic oscillator right-hand side
syms x(t) y(t)
f = odeFunction([y; -x], [x; y]);
f(0, [1; 2])
Output
ans = 2×1
2
-1
Notes
Passing the output of odeToVectorField (whose state is written Y[1], Y[2]) is not accepted in MatLivre; pass the symbolic functions as vars instead.
See also
odeToVectorField daeFunction matlabFunction ode45 massMatrixForm