This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.


Differential equations and systems solver

Character vector inputs are not recommended. Instead, use syms to declare variables and replace inputs such as dsolve('Dy = y') with syms y(t); dsolve(diff(y,t) == y).




S = dsolve(eqn) solves the differential equation eqn, where eqn is a symbolic equation. Use diff and == to represent differential equations. For example, diff(y,x) == y represents the equation dy/dx=y. Solve a system of differential equations by specifying eqn as a vector of those equations.


S = dsolve(eqn,cond) solves eqn with the initial or boundary condition cond.


S = dsolve(eqn,cond,Name,Value) uses additional options specified by one or more Name,Value pair arguments.


[y1,...,yN] = dsolve(___) assigns the solutions to the variables y1,...,yN.


Solve Differential Equation

Specify a differential equation by using == and represent differentiation by using the diff function. Then, solve the equation by using dsolve.

Solve the equation dydt=ay.

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

C2 is a constant. You can eliminate constants by specifying conditions. See Solve Differential Equation with Condition.

For more examples, see Solve a Single Differential Equation. For a complex workflow involving differential equations, see Solving Partial Differential Equations.

Solve Higher-Order Differential Equation

Specify the second-order derivative of a function y by using diff(y,t,2) or diff(y,t,t). Similarly, specify the n-th order derivative by using diff(y,t,n).

Solve the equation d2ydt2=ay.

syms y(t) a
eqn = diff(y,t,2) == a*y;
ySol(t) = dsolve(eqn)
ySol(t) =
C5*exp(a^(1/2)*t) + C6*exp(-a^(1/2)*t)

C5 and C6 are constants. You can eliminate constants by specifying conditions. See Solve Differential Equation with Condition.

Solve Differential Equation with Condition

Specify conditions as the second input to dsolve by using the == operator. Specifying conditions eliminates arbitrary constants, such as C1, C2,... from the solution.

Solve the equation dydt=ay with the condition y(0)=5.

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

Solve the second-order differential equation d2ydt2=a2y with two conditions, y(0)=b and y'(0)=1. Create the second 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) =
(exp(a*t)*(a*b + 1))/(2*a) + (exp(-a*t)*(a*b - 1))/(2*a)

Since two conditions are specified here, constants are eliminated from the solution of the second-order equation. 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 a system of differential equations by specifying the equations as a vector. dsolve returns a structure containing the solutions.

Solve the system of equations


syms y(t) z(t)
eqns = [diff(y,t)==z, diff(z,t)==-y];
sol = dsolve(eqns)
sol = 
  struct with fields:

    z: [1×1 sym]
    y: [1×1 sym]

Access the solutions by addressing the elements of the structure.

soly(t) = sol.y
soly(t) =
C2*cos(t) + C1*sin(t)
solz(t) = sol.z
solz(t) =
C1*cos(t) - C2*sin(t)

Assign Outputs to Functions or Variables

When solving for multiple functions, dsolve returns a structure by default. Alternatively, you can directly assign solutions to functions or variables by specifying the outputs explicitly as a vector. dsolve sorts 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) =
C2*cos(t) + C1*sin(t)
zSol(t) =
C1*cos(t) - C2*sin(t)

When No Solutions Are Found

If dsolve cannot find an explicit or implicit solution, then dsolve issues a warning and returns an empty sym. Returning an empty symbolic object does not mean that no solutions exist.

syms y(x)
eqn = exp(diff(y)) == 0;
 Warning: Explicit solution could not be found. 
ans =
[ empty sym ]

Turn Off Internal Simplifications for Complete Results

By default, dsolve applies simplifications that are not generally correct, but produce simpler solutions. For details, see Algorithms. Instead, obtain complete results by turning off these simplifications.

Solve dydt=ay+y where y(a)=1 with and without simplifications. Turn off simplifications by setting ‘IgnoreAnalyticConstraints' to false.

syms a y(t)
eqn = diff(y) == a/sqrt(y) + y;
cond = y(a) == 1;
withSimplifications = dsolve(eqn, cond)
withSimplifications =
(exp((3*t)/2 - (3*a)/2 + log(a + 1)) - a)^(2/3)
withoutSimplifications = dsolve(eqn, cond, 'IgnoreAnalyticConstraints', false)
withoutSimplifications =
piecewise(pi/2 < angle(-a), {piecewise(in(C11, 'integer'),...
 (- a + exp((3*t)/2 - (3*a)/2 + log(a + 1) + pi*C11*2i))^(2/3))},...
 angle(-a) <= -pi/2, {piecewise(in(C12, 'integer'),...
 (- a + exp((3*t)/2 - (3*a)/2 + log(a + 1) + pi*C12*2i))^(2/3))},...
 angle(-a) in Dom::Interval(-pi/2, [pi/2]), {piecewise(in(C13, 'integer'),...
 (- a + exp((3*t)/2 - (3*a)/2 + log(a + 1) + pi*C13*2i))^(2/3))})

withSimplifications is easy to use but incomplete, while withoutSimplifications includes special cases but is not easy to use.

Further, for certain equations, dsolve cannot find an explicit solution if you set ‘IgnoreAnalyticConstraints' to false.

Input Arguments

collapse all

Differential equation, specified as a symbolic equation or a vector of symbolic equations.

Specify a differential equation by using the == operator. 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 as syms y(x). Thus, to solve d2y(x)/dx2 = x*y(x), enter:

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

Specify a system of differential equations by using a vector of equations, such as dsolve([diff(y,t) == z, diff(z,t) == -y]).

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 and assign the diff call to a variable. Then create conditions by using that variable. For an example, see Solve Differential Equation with Condition.

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 arbitrary constants C1, C2,....

Name-Value Pair Arguments

Specify optional comma-separated 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.

Example: 'IgnoreAnalyticConstraints',false does not apply internal simplifications.

collapse all

By default, the solver applies simplifications while solving the differential equation. These simplifications might not be generally valid. Therefore, by default, the solver does not guarantee the completeness of results. For 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.

If you do not set ‘IgnoreAnalyticConstraints' to false, always verify results returned by the dsolve command.

Maximum degree of polynomial equations for which 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.

Output Arguments

collapse all

Solutions of differential equation, returned as a symbolic expression or a vector of symbolic expressions. The size of S is the number of solutions.

Variables storing solutions of differential equation, returned as a vector of symbolic variables. The number of output variables must equal the number of dependent variables in a system. dsolve sorts the dependent variables alphabetically, and then assigns the solutions for the variables to output variables or symbolic arrays.

More About

collapse all


  • If dsolve cannot find a closed-form (explicit) solution, it attempts to find an implicit solution. When dsolve returns an implicit solution, it issues this warning:

    Warning: Explicit solution could not be found;
    implicit solution returned.
  • 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.


If you do not set ‘IgnoreAnalyticConstraints' to false, then dsolve applies 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 = ac·bc.

  • log(ab) = 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:

      (ab)c = ab·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(ex) = 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

    • Wk(x·ex) = x for all values of k

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

  • The solutions of polynomial equations must be complete.

Introduced before R2006a

Was this topic helpful?