# dsolve

Solve system of differential equations

## Description

uses additional options specified by one or more `S`

= dsolve(___,`Name=Value`

)`Name=Value`

arguments.

## Examples

### Solve Differential Equation

Solve the first-order differential equation $\frac{\mathit{dy}}{\mathit{dt}}=\mathit{ay}$.

Specify the first-order derivative by using `diff`

and the equation by using ==. Then, solve the equation by using `dsolve`

.

syms y(t) a eqn = diff(y,t) == a*y; S = dsolve(eqn)

`S = $${C}_{1}\hspace{0.17em}{\mathrm{e}}^{a\hspace{0.17em}t}$$`

The solution includes a constant. To eliminate constants, see Solve Differential Equations with Conditions. For a full workflow, see Solve Partial Differential Equation of Tsunami Model.

### Solve Second-Order Differential Equation

Solve the second-order differential equation $\frac{{\mathit{d}}^{2}\mathit{y}}{{\mathit{dt}}^{2}}=\mathit{ay}$.

Specify the second-order derivative of y by using `diff(y,t,2)`

and the equation by using `==`

. Then, solve the equation by using `dsolve`

.

syms y(t) a eqn = diff(y,t,2) == a*y; ySol(t) = dsolve(eqn)

`ySol(t) = $${C}_{1}\hspace{0.17em}{\mathrm{e}}^{-\sqrt{a}\hspace{0.17em}t}+{C}_{2}\hspace{0.17em}{\mathrm{e}}^{\sqrt{a}\hspace{0.17em}t}$$`

### Solve Differential Equations with Conditions

Solve the first-order differential equation $\frac{\mathit{dy}}{\mathit{dt}}=\mathit{ay}$ with the initial condition $$y(0)=5$$.

Specify the initial condition as the second input to `dsolve`

by using the `==`

operator. Specifying condition eliminates arbitrary constants, such as `C1`

, `C2`

, `...`

, from the solution.

syms y(t) a eqn = diff(y,t) == a*y; cond = y(0) == 5; ySol(t) = dsolve(eqn,cond)

`ySol(t) = $$5\hspace{0.17em}{\mathrm{e}}^{a\hspace{0.17em}t}$$`

Next, solve the second-order differential equation $\frac{{\mathit{d}}^{2}\mathit{y}}{{\mathit{dt}}^{2}}={\mathit{a}}^{2}\mathit{y}$ with the initial conditions $$y(0)=b$$ and $${y}^{\prime}(0)=1$$.

Specify the second initial condition by assigning `diff(y,t)`

to `Dy`

and then using `Dy(0) == 1`

.

syms y(t) a b eqn = diff(y,t,2) == a^2*y; Dy = diff(y,t); cond = [y(0)==b, Dy(0)==1]; ySol(t) = dsolve(eqn,cond)

ySol(t) =$$\frac{{\mathrm{e}}^{a\hspace{0.17em}t}\hspace{0.17em}\left(a\hspace{0.17em}b+1\right)}{2\hspace{0.17em}a}+\frac{{\mathrm{e}}^{-a\hspace{0.17em}t}\hspace{0.17em}\left(a\hspace{0.17em}b-1\right)}{2\hspace{0.17em}a}$$

This second-order differential equation has two specified conditions, so constants are eliminated from the solution. In general, to eliminate constants from the solution, the number of conditions must equal the order of the equation.

### Solve System of Differential Equations

Solve the system of differential equations

$$\begin{array}{l}\frac{\mathit{dy}}{\mathit{dt}}=\mathit{z}\\ \frac{\mathit{dz}}{\mathit{dt}}=-\mathit{y}.\end{array}$$

Specify the system of equations as a vector. `dsolve`

returns a structure containing the solutions.

syms y(t) z(t) eqns = [diff(y,t) == z, diff(z,t) == -y]; S = dsolve(eqns)

`S = `*struct with fields:*
z: C2*cos(t) - C1*sin(t)
y: C1*cos(t) + C2*sin(t)

Access the solutions by addressing the elements of the structure.

ySol(t) = S.y

`ySol(t) = $${C}_{1}\hspace{0.17em}\mathrm{cos}\left(t\right)+{C}_{2}\hspace{0.17em}\mathrm{sin}\left(t\right)$$`

zSol(t) = S.z

`zSol(t) = $${C}_{2}\hspace{0.17em}\mathrm{cos}\left(t\right)-{C}_{1}\hspace{0.17em}\mathrm{sin}\left(t\right)$$`

### Assign Outputs to Functions or Variables

When solving for multiple functions, `dsolve`

returns a structure by default. Alternatively, you can assign solutions to functions or variables directly by explicitly specifying the outputs as a vector. `dsolve`

sorts the outputs in alphabetical order using `symvar`

.

Solve a system of differential equations and assign the outputs to functions.

syms y(t) z(t) eqns = [diff(y,t)==z, diff(z,t)==-y]; [ySol(t),zSol(t)] = dsolve(eqns)

`ySol(t) = $${C}_{1}\hspace{0.17em}\mathrm{cos}\left(t\right)+{C}_{2}\hspace{0.17em}\mathrm{sin}\left(t\right)$$`

`zSol(t) = $${C}_{2}\hspace{0.17em}\mathrm{cos}\left(t\right)-{C}_{1}\hspace{0.17em}\mathrm{sin}\left(t\right)$$`

### Find Explicit and Implicit Solutions of Differential Equation

Solve the differential equation $$\frac{\partial}{\partial t}y(t)={e}^{-y(t)}+y(t)$$. `dsolve`

returns an explicit solution in terms of a Lambert W function that has a constant value.

```
syms y(t)
eqn = diff(y) == y+exp(-y)
```

eqn(t) =$$\frac{\partial}{\partial t}\mathrm{}y\left(t\right)={\mathrm{e}}^{-y\left(t\right)}+y\left(t\right)$$

sol = dsolve(eqn)

`sol = $${\mathrm{W}\text{lambertw}}_{0}\left(-1\right)$$`

To return implicit solutions of the differential equation, set the `Implicit`

option to `true`

. An implicit solution has the form $$F(y(t))=g(t)$$.

sol = dsolve(eqn,Implicit=true)

sol =$$\left(\begin{array}{c}\left({\int \frac{{\mathrm{e}}^{y}}{y\hspace{0.17em}{\mathrm{e}}^{y}+1}\mathrm{}\mathrm{d}y|}_{y=y\left(t\right)}\right)={C}_{1}+t\\ {\mathrm{e}}^{-y\left(t\right)}\hspace{0.17em}\left({\mathrm{e}}^{y\left(t\right)}\hspace{0.17em}y\left(t\right)+1\right)=0\end{array}\right)$$

### Find Implicit Solution When No Explicit Solution Is Found

If `dsolve`

cannot find an explicit solution of a differential equation analytically, then it returns an empty symbolic array. You can solve the differential equation by using MATLAB® numerical solver, such as `ode45`

. For more information, see Solve a Second-Order Differential Equation Numerically.

```
syms y(x)
eqn = diff(y) == (x-exp(-x))/(y(x)+exp(y(x)));
S = dsolve(eqn)
```

Warning: Unable to find symbolic solution.

S = [ empty sym ]

Alternatively, you can try finding an implicit solution of the differential equation by specifying the `Implicit`

option to `true`

. An implicit solution has the form $$F(y(x))=g(x)$$.

S = dsolve(eqn,Implicit=true)

S =$${\mathrm{e}}^{y\left(x\right)}+\frac{{y\left(x\right)}^{2}}{2}={C}_{1}+{\mathrm{e}}^{-x}+\frac{{x}^{2}}{2}$$

### Include Special Cases by Turning Off Internal Simplifications

Solve the differential equation $\frac{\mathit{dy}}{\mathit{dt}}=\frac{\mathit{a}}{\sqrt{\mathit{y}}}+\mathit{y}$ with condition $$y(a)=1$$. By default, `dsolve`

applies simplifications that are not generally correct, but produce simpler solutions. For more details, see Algorithms.

syms a y(t) eqn = diff(y) == a/sqrt(y) + y; cond = y(a) == 1; ySimplified = dsolve(eqn,cond)

ySimplified =$${\left({\mathrm{e}}^{\frac{3\hspace{0.17em}t}{2}-\frac{3\hspace{0.17em}a}{2}+\mathrm{log}\left(a+1\right)}-a\right)}^{2/3}$$

To return the solutions that include all possible values of the parameter $$a$$, turn off simplifications by setting `IgnoreAnalyticConstraints`

to `false`

.

yNotSimplified = dsolve(eqn,cond,IgnoreAnalyticConstraints=false)

yNotSimplified =$$\begin{array}{l}\{\begin{array}{cl}\{\begin{array}{cl}\left\{{\sigma}_{1}\right\}& \text{if}-\frac{\pi}{2}{\sigma}_{2}\\ \left\{{\sigma}_{1},-{\left(-a+{\mathrm{e}}^{\frac{3\hspace{0.17em}t}{2}-\frac{3\hspace{0.17em}a}{2}+\mathrm{log}\left(a+{\left(-\frac{1}{2}+{\sigma}_{3}\right)}^{3/2}\right)+2\hspace{0.17em}\pi \hspace{0.17em}{C}_{2}\hspace{0.17em}\mathrm{i}}\right)}^{2/3}\hspace{0.17em}\left(\frac{1}{2}+{\sigma}_{3}\right)\right\}& \text{if}{\sigma}_{2}\le -\frac{\pi}{2}\end{array}& \text{if}{C}_{2}\in \mathbb{Z}\\ \varnothing & \text{if}{C}_{2}\notin \mathbb{Z}\end{array}\\ \\ \mathrm{where}\\ \\ \mathrm{}{\sigma}_{1}={\left(-a+{\mathrm{e}}^{\frac{3\hspace{0.17em}t}{2}-\frac{3\hspace{0.17em}a}{2}+\mathrm{log}\left(a+1\right)+2\hspace{0.17em}\pi \hspace{0.17em}{C}_{2}\hspace{0.17em}\mathrm{i}}\right)}^{2/3}\\ \\ \mathrm{}{\sigma}_{2}=\text{angle}\left({\mathrm{e}}^{\frac{3\hspace{0.17em}{C}_{1}}{2}+\frac{3\hspace{0.17em}t}{2}}-a\right)\\ \\ \mathrm{}{\sigma}_{3}=\frac{\sqrt{3}\hspace{0.17em}\mathrm{i}}{2}\end{array}$$

### Find Series Solution of Differential Equation

Solve the second-order differential equation $$({x}^{2}-1{)}^{2}\frac{{\partial}^{2}}{\partial {x}^{2}}y(x)+(x+1)\frac{\partial}{\partial x}y(x)-y(x)=0$$. `dsolve`

returns a solution that contains a term with unevaluated integral.

```
syms y(x)
eqn = (x^2-1)^2*diff(y,2) + (x+1)*diff(y) - y == 0;
S = dsolve(eqn)
```

S =$${C}_{2}\hspace{0.17em}\left(x+1\right)+{C}_{1}\hspace{0.17em}\left(x+1\right)\hspace{0.17em}\int \frac{{\mathrm{e}}^{\frac{1}{2\hspace{0.17em}\left(x-1\right)}}\hspace{0.17em}{\left(1-x\right)}^{1/4}}{{\left(x+1\right)}^{9/4}}\mathrm{}\mathrm{d}x$$

To return series solutions of the differential equation around $$x=-1$$, set the `ExpansionPoint`

to `-1`

. `dsolve`

returns two linearly independent solutions in terms of a Puiseux series expansion.

S = dsolve(eqn,ExpansionPoint=-1)

S =$$\left(\begin{array}{c}\frac{1}{{\left(x+1\right)}^{1/4}}-\frac{5\hspace{0.17em}{\left(x+1\right)}^{3/4}}{4}+\frac{5\hspace{0.17em}{\left(x+1\right)}^{7/4}}{48}+\frac{5\hspace{0.17em}{\left(x+1\right)}^{11/4}}{336}+\frac{115\hspace{0.17em}{\left(x+1\right)}^{15/4}}{33792}+\frac{169\hspace{0.17em}{\left(x+1\right)}^{19/4}}{184320}\\ x+1\end{array}\right)$$

Find other series solutions around the expansion point $$\infty $$ by setting `ExpansionPoint`

to `Inf`

.

S = dsolve(eqn,ExpansionPoint=Inf)

S =$$\left(\begin{array}{c}\frac{1}{6\hspace{0.17em}{x}^{2}}+\frac{1}{8\hspace{0.17em}{x}^{4}}+\frac{1}{90\hspace{0.17em}{x}^{5}}+1\\ x-\frac{1}{6\hspace{0.17em}{x}^{2}}-\frac{1}{8\hspace{0.17em}{x}^{4}}\end{array}\right)$$

The default truncation order of the series expansion is 6. To obtain more terms in the Puiseux series solutions, set `Order`

to 8.

S = dsolve(eqn,ExpansionPoint=Inf,Order=8)

S =$$\left(\begin{array}{c}\frac{1}{6\hspace{0.17em}{x}^{2}}+\frac{1}{8\hspace{0.17em}{x}^{4}}+\frac{1}{90\hspace{0.17em}{x}^{5}}+\frac{37}{336\hspace{0.17em}{x}^{6}}+\frac{37}{1680\hspace{0.17em}{x}^{7}}+1\\ x-\frac{1}{6\hspace{0.17em}{x}^{2}}-\frac{1}{8\hspace{0.17em}{x}^{4}}-\frac{1}{90\hspace{0.17em}{x}^{5}}-\frac{37}{336\hspace{0.17em}{x}^{6}}\end{array}\right)$$

### Specify Initial Condition for Function with Different One-Sided Limits

Solve the differential equation $\frac{\mathit{dy}}{\mathit{dx}}=\frac{1}{{\mathit{x}}^{2}}{\mathit{e}}^{-\frac{1}{\mathit{x}}}$ without specifying the initial condition.

```
syms y(x)
eqn = diff(y) == exp(-1/x)/x^2;
ySol(x) = dsolve(eqn)
```

ySol(x) =$${C}_{1}+{\mathrm{e}}^{-\frac{1}{x}}$$

To eliminate constants from the solution, specify the initial condition $\mathit{y}\left(0\right)=1$.

cond = y(0) == 1; S = dsolve(eqn,cond)

S =$${\mathrm{e}}^{-\frac{1}{x}}+1$$

The function ${\mathit{e}}^{-\frac{1}{\mathit{x}}}$ in the solution `ySol(x)`

has different one-sided limits at $$x=0$$. The function has a right-side limit, $\underset{\mathit{x}\to {0}^{+}}{\mathrm{lim}}\text{\hspace{0.17em}}{\mathit{e}}^{-\frac{1}{\mathit{x}}}=0$, but it has undefined left-side limit, $\underset{\mathit{x}\to {0}^{-}}{\mathrm{lim}}\text{\hspace{0.17em}}{\mathit{e}}^{-\frac{1}{\mathit{x}}}=\infty $.

When you specify the condition `y(x0)`

for a function with different one-sided limits at `x0`

, `dsolve`

treats the condition as a limit from the right, $\mathrm{lim}\text{\hspace{0.17em}}\mathit{x}\to {\mathit{x}}_{0}^{+}$.

## Input Arguments

`eqn`

— Differential equation or system of equations

symbolic equation | vector of symbolic equations

Differential equation or system of equations, specified as a symbolic equation or a vector of
symbolic equations. Specify a differential equation by using the `==`

operator. If `eqn`

is a symbolic expression (without the right side),
the solver assumes that the right side is 0, and solves the equation ```
eqn ==
0
```

.

In the equation, represent differentiation by using `diff`

. For example, `diff(y,x)`

differentiates the
symbolic function `y(x)`

with respect to `x`

. Create
the symbolic function `y(x)`

by using `syms`

and solve the equation
`d`

using ^{2}y(x)/dx^{2} =
x*y(x)`dsolve`

.

```
syms y(x)
S = dsolve(diff(y,x,2) == x*y)
```

Specify a system of differential equations by using a vector of equations, as in ```
syms
y(t) z(t); S = dsolve([diff(y,t) == z, diff(z,t) == -y])
```

. Here,
`y`

and `z`

must be symbolic functions that depend
on symbolic variables, which are `t`

in this case. The right side must
be symbolic expressions that depend on `t`

, `y`

and
`z`

. Note that Symbolic Math Toolbox™ currently does not support composite symbolic functions, that is, symbolic
functions that depend on another symbolic functions.

`cond`

— Initial or boundary condition

symbolic equation | vector of symbolic equations

Initial or boundary condition, specified as a symbolic equation or vector of symbolic equations.

When a condition contains a derivative, represent the derivative with `diff`

. Assign the `diff`

call to a variable and use the
variable to specify the condition. For example, see Solve Differential Equations with Conditions.

Specify multiple conditions by using a vector of equations. If the number of conditions is
less than the number of dependent variables, the solutions contain the arbitrary
constants `C1`

, `C2`

,`...`

.

### Name-Value Arguments

Specify optional pairs of arguments as
`Name1=Value1,...,NameN=ValueN`

, where `Name`

is
the argument name and `Value`

is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.

**Example: **`IgnoreAnalyticConstraints=false`

does not apply internal
simplifications.

*
Before R2021a, use commas to separate each name and value, and enclose*
`Name`

*in quotes.*

`ExpansionPoint`

— Expansion point of Puiseux series solution

`0`

(default) | number | symbolic number | symbolic variable | symbolic function | symbolic expression

Expansion point of a Puiseux series solution, specified as a number, or a symbolic number, variable, function, or expression. Specifying this option returns the solution of a differential equation in terms of a Puiseux series (a power series that allows negative and fractional exponents). The expansion point cannot depend on the series variable. For example, see Find Series Solution of Differential Equation.

**Data Types: **`single`

| `double`

| `sym`

**Complex Number Support: **Yes

`IgnoreAnalyticConstraints`

— Option to use internal simplifications

`true`

(default) | `false`

Option to use internal simplifications, specified as `true`

or
`false`

.

By default, the solver applies simplifications while solving the differential
equation, which could lead to results not generally valid. In other words, this option
applies mathematical identities that are convenient, but the results might not hold
for all possible values of the variables. Therefore, by default, the solver does not
guarantee the completeness of results. If `IgnoreAnalyticConstraints`

is `true`

, always verify results returned by the
`dsolve`

function. For more details, see Algorithms.

To solve ordinary differential equations without these simplifications, set
`IgnoreAnalyticConstraints`

to `false`

. Results
obtained with `IgnoreAnalyticConstraints`

set to
`false`

are correct for all values of the arguments. For certain
equations, `dsolve`

might not return an explicit solution if you set
`IgnoreAnalyticConstraints`

to `false`

.

`Implicit`

— Option to return implicit solution

`false`

(default) | `true`

Option to return an implicit solution, specified as `false`

or
`true`

. For a differential equation with variables *x* and *y*(*x*), an implicit solution has the form *F*(*y*(*x*)) =
*g*(*x*).

By default, the solver tries to find an explicit solution *y*(*x*) =
*f*(*x*) analytically when solving a differential equation. If
`dsolve`

cannot find an explicit solution, then you can try finding
a solution in implicit form by specifying the `Implicit`

option to
`true`

.

`MaxDegree`

— Maximum degree of polynomial equation for which solver uses explicit formulas

2 (default) | positive integer smaller than 5

Maximum degree of polynomial equations for which the solver uses explicit formulas, specified
as a positive integer smaller than 5. `dsolve`

does not use
explicit formulas when solving polynomial equations of degrees larger than
`MaxDegree`

.

`Order`

— Truncation order of Puiseux series solution

`0`

(default) | positive integer | symbolic positive integer

Truncation order of a Puiseux series solution, specified as a positive integer or
a symbolic positive integer. Specifying this option returns the solution of a
differential equation in terms of a Puiseux series (a power series that allow negative
and fractional exponents). The truncation order *n* is the exponent in the *O*-term: $$O({\mathrm{var}}^{n})$$ or $$O({\mathrm{var}}^{-n})$$.

## Output Arguments

`S`

— Solutions of differential equation

symbolic expression | vector of symbolic expressions

Solutions of differential equation, returned as a symbolic expression or a vector of symbolic
expressions. The size of `S`

is the number of solutions.

`y1,...,yN`

— Variables storing solutions of differential equations

vector of symbolic variables

Variables storing solutions of differential equations, returned as a vector of
symbolic variables. The number of output variables must equal the number of dependent
variables in a system of equations. `dsolve`

sorts the dependent
variables alphabetically, and then assigns the solutions for the variables to output
variables or symbolic arrays.

## Tips

If

`dsolve`

cannot find an explicit or implicit solution, then it issues a warning and returns the empty`sym`

. In this case, try to find a numeric solution using the MATLAB^{®}`ode23`

or`ode45`

function. Sometimes, the output is an equivalent lower-order differential equation or an integral.`dsolve`

does not always return complete solutions even if`IgnoreAnalyticConstraints`

is`false`

.If

`dsolve`

returns a function that has different one-sided limits at`x0`

and you specify the condition`y(x0)`

, then`dsolve`

treats the condition as a limit from the right, $$\mathrm{lim}x\to {x}_{0}^{+}\text{}$$.

## Algorithms

If you do not set `IgnoreAnalyticConstraints`

to `false`

,
then `dsolve`

applies some of these rules while solving the
equation:

log(

*a*) + log(*b*) = log(*a*·*b*) for all values of*a*and*b*. In particular, the following equality is applied for all values of*a*,*b*, and*c*:(

*a*·*b*)^{c}=*a*^{c}·*b*^{c}.log(

*a*^{b}) =*b*·log(*a*) for all values of*a*and*b*. In particular, the following equality is applied for all values of*a*,*b*, and*c*:(

*a*^{b})^{c}=*a*^{b·c}.If

*f*and*g*are standard mathematical functions and*f*(*g*(*x*)) =*x*for all small positive numbers,*f*(*g*(*x*)) =*x*is assumed to be valid for all complex*x*. In particular:log(

*e*^{x}) =*x*asin(sin(

*x*)) =*x*, acos(cos(*x*)) =*x*, atan(tan(*x*)) =*x*asinh(sinh(

*x*)) =*x*, acosh(cosh(*x*)) =*x*, atanh(tanh(*x*)) =*x*W

_{k}(*x*·*e*^{x}) =*x*for all branch indices*k*of the Lambert W function.

The solver can multiply both sides of an equation by any expression except

`0`

.The solutions of polynomial equations must be complete.

## Version History

**Introduced before R2006a**

### R2020a: Return solutions of differential equations in implicit form or truncated series expansion

With `dsolve`

:

Use the

`Implicit`

name-value argument to return implicit solutions of differential equations.Use the

`ExpansionPoint`

and`Order`

name-value arguments to specify the expansion point and truncation order of Puiseux series solutions of differential equations.

### R2019b: `dsolve`

will no longer support character vector or string inputs

`dsolve`

will not accept equations as strings or character vectors in a
future release. Instead, use symbolic expressions or `sym`

objects to
define differential equations. For example, replace inputs such as ```
dsolve('Dy =
exp(y)')
```

with `syms y(t); dsolve(diff(y,t) == exp(y))`

.

## See Also

`functionalDerivative`

| `isolate`

| `linsolve`

| `ode23`

| `ode45`

| `odeToVectorField`

| `solve`

| `syms`

| `vpasolve`

### External Websites

## MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)