Ordinary differential equation and system solver
S = dsolve(eqn)
S = dsolve(eqn,cond)
S = dsolve(eqn,cond,Name,Value)
Y = dsolve(eqns)
Y = dsolve(eqns,conds)
Y = dsolve(eqns,conds,Name,Value)
[y1,...,yN] = dsolve(eqns)
[y1,...,yN] = dsolve(eqns,conds)
[y1,...,yN] = dsolve(eqns,conds,Name,Value)
solves
the ordinary differential equation S
= dsolve(eqn
)eqn
. Here eqn
is
a symbolic equation containing diff
to indicate
derivatives. Alternatively, you can use a string with the letter D
indicating
derivatives. For example, syms y(x); dsolve(diff(y) == y
+ 1)
and dsolve('Dy = y + 1','x')
both
solve the equation dy/dx = y + 1
with respect to
the variable x
. Also, eqn
can
be an array of such equations or strings.
solves
the ordinary differential equation S
= dsolve(eqn
,cond
)eqn
with the
initial or boundary condition cond
.
uses
additional options specified by one or more S
= dsolve(eqn
,cond
,Name,Value
)Name,Value
pair
arguments.
solves
the system of ordinary differential equations Y
= dsolve(eqns
)eqns
and
returns a structure array that contains the solutions. The number
of fields in the structure array corresponds to the number of independent
variables in the system.
solves
the system of ordinary differential equations Y
= dsolve(eqns
,conds
)eqns
with
the initial or boundary conditions conds
.
uses
additional options specified by one or more Y
= dsolve(eqns
,conds
,Name,Value
)Name,Value
pair
arguments.
[
solves
the system of ordinary differential equations y1,...,yN
] = dsolve(eqns
)eqns
and
assigns the solutions to the variables y1,...,yN
.
[
solves
the system of ordinary differential equations y1,...,yN
] = dsolve(eqns
,conds
)eqns
with
the initial or boundary conditions conds
.
[
uses
additional options specified by one or more y1,...,yN
] = dsolve(eqns
,conds
,Name,Value
)Name,Value
pair
arguments.

Symbolic equation, string representing an ordinary differential equation, or array of symbolic equations or strings. When representing syms y(x)
dsolve(diff(y, 2) == x*y) When representing dsolve('D2y = x*y','x') or dsolve('D2y == x*y','x') 

Equation or string representing an initial or boundary condition.
If you use equations, assign expressions with Dy = diff(y); D2y = diff(y, 2); Then define initial conditions using symbolic equations, such
as If you represent initial and boundary conditions as strings,
you do not need to create intermediate variables. In this case, follow
the same rules as you do when creating an equation 

Symbolic equations or strings separated by commas and representing a system of ordinary differential equations. Each equation or string represents an ordinary differential equation. 

Symbolic equations or strings separated by commas and representing
initial or boundary conditions or both types of conditions. Each equation
or string represents an initial or boundary condition. If the number
of the specified conditions is less than the number of dependent variables,
the resulting solutions contain arbitrary constants 
Specify optional commaseparated pairs of Name,Value
arguments.
Name
is the argument
name and Value
is the corresponding
value. Name
must appear
inside single quotes (' '
).
You can specify several name and value pair
arguments in any order as Name1,Value1,...,NameN,ValueN
.

By default, the solver applies the purely algebraic simplifications
to the expressions on both sides of equations. These simplifications
might not be generally valid. Therefore, by default the solver does
not guarantee general correctness and completeness of the results.
To solve ordinary differential equations without additional assumptions,
set If you do not set Default: 

Do not use explicit formulas that involve radicals when solving polynomial equations of degrees larger than the specified value. This value must be a positive integer smaller than 5. Default: 2 

Symbolic array that contains solutions of an equation. The size of a symbolic array corresponds to the number of the solutions. 

Structure array that contains solutions of a system of equations. The number of fields in the structure array corresponds to the number of independent variables in a system. 

Variables to which the solver assigns the solutions of a system of equations. The number of output variables or symbolic arrays must equal the number of independent variables in a system. The toolbox sorts independent variables alphabetically, and then assigns the solutions for these variables to output variables or symbolic arrays. 
Solve these ordinary differential equations. Use ==
to
create an equation, and diff
to indicate differentiation:
syms a x(t) dsolve(diff(x) == a*x)
ans = C2*exp(a*t)
syms f(t) dsolve(diff(f) == f + sin(t))
ans = C5*exp(t)  (2^(1/2)*cos(t  pi/4))/2
Solve this ordinary differential equation with the initial condition y(0) = b
:
syms a b y(t) dsolve(diff(y) == a*y, y(0) == b)
Specifying the initial condition lets you eliminate arbitrary
constants, such as C1
, C2
,...
:
ans = b*exp(a*t)
Solve this ordinary differential equation with the initial and boundary conditions. To specify a condition that contains a derivative, assign the derivative to a variable:
syms a y(t) Dy = diff(y); dsolve(diff(y, 2) == a^2*y, y(0) == 1, Dy(pi/a) == 0)
Because the equation contains the secondorder derivative d^{2}y/dt^{2}
,
specifying two conditions lets you eliminate arbitrary constants in
the solution:
ans = exp(a*t*1i)/2 + exp(a*t*1i)/2
Solve this system of ordinary differential equations:
syms x(t) y(t) z = dsolve(diff(x) == y, diff(y) == x)
When you assign the solution of a system of equations to a single
output, dsolve
returns a structure containing the
solutions:
z = y: [1x1 sym] x: [1x1 sym]
To see the results, enter z.x
and z.y
:
z.x
ans = C12*cos(t) + C11*sin(t)
z.y
ans = C11*cos(t)  C12*sin(t)
By default, the solver applies a set of purely algebraic simplifications that are not correct in general, but that can produce simple and practical solutions:
syms a y(t) dsolve(diff(y) == a/sqrt(y) + y, y(a) == 1)
ans = (exp((3*t)/2  (3*a)/2 + log(a + 1))  a)^(2/3)
To obtain complete and generally correct solutions, set the
value of IgnoreAnalyticConstraints
to false
:
dsolve(diff(y) == a/sqrt(y) + y, y(a) == 1, 'IgnoreAnalyticConstraints', false)
Warning: The solutions are subject to the following conditions: PI/2 < angle(a) in(C22, 'integer') . ans = ( a + exp((3*t)/2  (3*a)/2 + log(a + 1) + pi*C22*2i))^(2/3)
If you apply algebraic simplifications, you can get explicit solutions for some equations for which the solver cannot compute them using strict mathematical rules:
syms y(t) dsolve(sqrt(diff(y)) == sqrt(y) + log(y^2))
Warning: Explicit solution could not be found; implicit solution returned. ans = 16*lambertw(0, 1/4)^2 16*lambertw(0, 1/4)^2 solve(int(1/(log(y^2) + y^(1/2))^2, y,... 'IgnoreSpecialCases', true,... 'IgnoreAnalyticConstraints', true)  t  C27 == 0, y)
versus
dsolve(sqrt(diff(y)) == sqrt(y) + log(y^2), 'IgnoreAnalyticConstraints', false)
Warning: Explicit solution could not be found; implicit solution returned. ans = solve(log(y^2) + y^(1/2) == 0, y) solve(int(1/(log(y^2) + y^(1/2))^2, y,... 'IgnoreSpecialCases', true)  t  C32 == 0, y)
When you solve a higherorder polynomial equation, the solver
sometimes uses RootOf
to return the results:
syms a y(x) dsolve(diff(y) == a/(y^2 + 1))
Warning: Explicit solution could not be found; implicit solution returned. ans = RootOf(z^3 + 3*z  3*a*x  3*C36, z)
To get an explicit solution for such equations, try calling
the solver with MaxDegree
. The option specifies
the maximum degree of polynomials for which the solver tries to return
explicit solutions. The default value is 2. By increasing this value,
you can get explicit solutions for higherorder polynomials. For example,
increase the value of MaxDegree
to 4 and get explicit
solutions instead of RootOf
for this equation:
s = dsolve(diff(y) == a/(y^2 + 1), 'MaxDegree', 4); pretty(s)
/ 1 \  #1     #1     / 1 \   sqrt(3)   + #1  1i   \ #1 / 1 #1    +      2 2 #1 2     / 1 \   sqrt(3)   + #1  1i   1 \ #1 / #1         \ 2 #1 2 2 / where / / 2 \ \1/3  3 C39 3 a x  9 (C39 + a x)   #1 ==   +  + sqrt  + 1   \ 2 2 \ 4 / /
If dsolve
can find neither an explicit nor
an implicit solution, then it issues a warning and returns the empty sym
:
syms y(x) dsolve(exp(diff(y)) == 0)
Warning: Explicit solution could not be found. ans = [ empty sym ]
Returning the empty symbolic object does not prove that there are no solutions.
Solve this equation specifying it as a string. By default, dsolve
assumes
that the independent variable is t
:
dsolve('Dy^2 + y^2 == 1')
ans = 1 1 cosh(C49 + t*1i) cosh(C45  t*1i)
Now solve this equation with respect to the variable s
:
dsolve('Dy^2 + y^2 == 1','s')
ans = 1 1 cosh(C57 + s*1i) cosh(C53  s*1i)
functionalDerivative
 linsolve
 ode23
 ode45
 odeToVectorField
 solve
 syms
 vpasolve