odeToVectorField

Rewrites a higher-order ODE as an equivalent first-order system.

Category: Mathematics > Equation Solving

Syntax

V = odeToVectorField(eqn)

Returns the right-hand side V of the first-order system Y' = V.

[V, S] = odeToVectorField(eqn)

Also returns S, the list of state variables.

Description

A solver such as ode45 takes first-order systems only. The substitution used here treats y, y', ... as separate states: for y'' + y = 0 the state is [y; Dy] and the system is [Dy; -y]. The equation must be solvable for its highest derivative.

Input arguments

eqn
Differential equation using diff of a symbolic function.

Output arguments

V
Symbolic column vector; entries are written with Y[1], Y[2], and so on.
S
State variables: the function and its derivatives up to one order lower than the equation.

Example

Second-order oscillator

syms y(t)
[V, S] = odeToVectorField(diff(y,t,2) + y == 0)
Output
V = 
 Y[2]
-Y[1]
S = 
 y
Dy

Notes

A single equation is supported; systems of several equations are not accepted in MatLivre.

See also

odeFunction dsolve ode45 reduceDifferentialOrder