odeToVectorField
Reduce order of differential equations to first-order
Support for character vector or string inputs will be removed in a future release. Instead, usesyms
to declare variables, and replace inputs such asodeToVectorField('D2y = x')
withsyms y(x), odeToVectorField(diff(y,x,2) == x)
.
Description
converts higher-order differential equationsV
= odeToVectorField(eqn1,...,eqnN
)eqn1,...,eqnN
to a system of first-order differential equations, returned as a symbolic vector.
[
convertsV
,S
] = odeToVectorField(eqn1,...,eqnN
)eqn1,...,eqnN
and returns two symbolic vectors. The first vectorV
is the same as the output of the previous syntax. The second vectorS
shows the substitutions made to obtainV
.
Examples
Input Arguments
Output Arguments
Tips
To solve the resulting system of first-order differential equations, generate a MATLAB®function handle using
matlabFunction
withV
as an input. Then, use the generated MATLAB function handle as an input for the MATLAB numerical solverode23
orode45
.odeToVectorField
can convert only quasi-linear differential equations. That is, the highest-order derivatives must appear linearly. For example,odeToVectorField
can converty*y″(t) = –t2because it can be rewritten asy″(t) = –t2/y. However, it cannot converty″(t)2= –t2orsin(y″(t)) = –t2.
Algorithms
To convert annth-order differential equation
into a system of first-order differential equations,odetovectorfield
makes these substitutions.
Using the new variables, it rewrites the equation as a system ofnfirst-order differential equations:
odeToVectorField
returns the right sides of these equations as the elements of vectorV
and the substitutions made as the second outputS
.