# odeToVectorField

Reduce order of differential equations to first-order

**Support for character vector or string inputs will be removed in a future release. Instead,
use syms to declare variables, and replace inputs
such as odeToVectorField('D2y = x') with syms y(x),
odeToVectorField(diff(y,x,2) == x).**

## Description

converts
higher-order differential equations `V`

= odeToVectorField(`eqn1,...,eqnN`

)`eqn1,...,eqnN`

to
a system of first-order differential equations, returned as a symbolic
vector.

`[`

converts `V`

,`S`

] =
odeToVectorField(`eqn1,...,eqnN`

)`eqn1,...,eqnN`

and
returns two symbolic vectors. The first vector `V`

is
the same as the output of the previous syntax. The second vector `S`

shows
the substitutions made to obtain `V`

.

## Examples

## Input Arguments

## Output Arguments

## Tips

To solve the resulting system of first-order differential equations, generate a MATLAB

^{®}function handle using`matlabFunction`

with`V`

as an input. Then, use the generated MATLAB function handle as an input for the MATLAB numerical solver`ode23`

or`ode45`

.`odeToVectorField`

can convert only quasi-linear differential equations. That is, the highest-order derivatives must appear linearly. For example,`odeToVectorField`

can convert*y***y*″(*t*) = –*t*^{2}because it can be rewritten as*y*″(*t*) = –*t*^{2}/*y*. However, it cannot convert*y*″(*t*)^{2}= –*t*^{2}or sin(*y*″(*t*)) = –*t*^{2}.

## Algorithms

To convert an *n*th-order differential equation

$${a}_{n}(t){y}^{(n)}+{a}_{n-1}(t){y}^{(n-1)}+\dots +{a}_{1}(t){y}^{\prime}+{a}_{0}(t)y+r(t)=0$$

into a system of first-order differential equations, `odetovectorfield`

makes
these substitutions.

$$\begin{array}{l}{Y}_{1}=y\\ {Y}_{2}={y}^{\prime}\\ {Y}_{3}={y}^{\u2033}\\ \dots \\ {Y}_{n-1}={y}^{(n-2)}\\ {Y}_{n}={y}^{(n-1)}\end{array}$$

Using the new variables, it rewrites the equation as a system
of *n* first-order differential equations:

$$\begin{array}{l}{Y}_{1}{}^{\prime}={y}^{\prime}={Y}_{2}\\ {Y}_{2}{}^{\prime}={y}^{\u2033}={Y}_{3}\\ \dots \\ {Y}_{n-1}{}^{\prime}={y}^{(n-1)}={Y}_{n}\\ {Y}_{n}{}^{\prime}=-\frac{{a}_{n-1}\left(t\right)}{{a}_{n}\left(t\right)}{Y}_{n}-\frac{{a}_{n-2}\left(t\right)}{{a}_{n}\left(t\right)}{Y}_{n-1}-\mathrm{...}-\frac{{a}_{1}\left(t\right)}{{a}_{n}\left(t\right)}{Y}_{2}-\frac{{a}_{0}\left(t\right)}{{a}_{n}\left(t\right)}{Y}_{1}+\frac{r\left(t\right)}{{a}_{n}\left(t\right)}\end{array}$$

`odeToVectorField`

returns the right sides
of these equations as the elements of vector `V`

and
the substitutions made as the second output `S`

.

## Version History

**Introduced in R2012a**

## See Also

`dsolve`

| `matlabFunction`

| `odeFunction`

| `ode23`

| `ode45`