# Solving differential equations: desolve deSolve dsolve

### 5.57.1 Solving differential equations: desolve deSolve dsolve

The desolve (or deSolve) command can solve:

- linear differential equations with constant coefficients,
- first order linear differential equations,
- first order differential equations without y,
- first order differential equations without x,
- first order differential equations with separable variables,
- first order homogeneous differential equations (y′=F(y/x)),
- first order differential equations with integrating factor,
- first order Bernoulli differential equations (a(x)y′+b(x)y=c(x)yn),
- first order Clairaut differential equations (y=x*y′+f(y′)).

deSolve is a synonym for desolve.

- desolve takes one mandatory arguments and two optional arguments:
  - de, a differential equation or list of differential equations, including any initial conditions.
  - Optionally, x, the variable (by default x).
  - Optionally, y, the unknown function (by default y). The unknown function can be given in variable form (such as y) or function form (such as y(x)), in which case the variable doesn’t have to be given as a separate argument.
- desolve(de ⟨,x,y⟩) returns the solution of the differential equation.

In the differential equations, the function y can be denoted by y or y(x), the derivative by y′, y′(x) or diff(y(x),x), etc.

#### Examples.

- Input:
  desolve(y’’+2*y’+y,y)
  Output:

  e−x | ⎛ ⎝ | c0 x+c1 | ⎞ ⎠

- Input:
  desolve([y’’+2*y’+y,y(0)=1,y’(0)=0],y)
  Output:

  e−x | ⎛ ⎝ | x+1 | ⎞ ⎠

- Input:
  desolve(diff(y(t),t$2)+2*diff(y(t),t)+y(t),y(t))
  or:
  desolve(diff(y(t),t$2)+2*diff(y(t),t)+y(t),t,y)
  Output:

  e−t | ⎛ ⎝ | c0 t+c1 | ⎞ ⎠

- Input:
  desolve([diff(y(t),t$2)+2*diff(y(t),t)+y(t),y(0)=1,y’(0)=0],y(t))
  or:
  desolve([diff(y(t),t$2)+2*diff(y(t),t)+y(t),y(0)=1,y’(0)=0],t,y)
  Output:

  e−t | ⎛ ⎝ | t+1 | ⎞ ⎠

- Solve:

  y″+y=cos(x)

  Input (typing twice prime for y’’):
  desolve(y’’+y=cos(x),y)
  or:
  desolve((diff(diff(y))+y)=(cos(x)),y)
  Output:

  c0 cosx+c1 sinx+

  2 x sinx+cosx
  4

  c_0, c_1 are the constants of integration: y(0)=c_0 y′(0)=c_1.
- If the variable is not x but t:
  Input:
  desolve(derive(derive(y(t),t),t)+y(t)=cos(t),t,y)
  Output:

  c0 cost+c1 sint+

  2 t sint+cost
  4

  c_0, c_1 are the constants of integration: y(0)=c_0 and y′(0)=c_1.
- Solve:

  y″+y=cos(x), y(0)=1

  Input:
  desolve([y’’+y=cos(x),y(0)=1],y)
  Output:

  3
  4

  cosx+c1 sinx+

  2 x sinx+cosx
  4

- Solve:

  y″+y=cos(x) (y(0))2=1

  Input:
  desolve([y’’+y=cos(x),y(0)^2=1],y)
  Output:

  ⎡
  ⎢
  ⎢
  ⎣

  3 cosx
  4

  +c1 sinx+

  2 x sinx+cosx
  4

  ,−

  5 cosx
  4

  +c1 sinx+

  2 x sinx+cosx
  4

  ⎤
  ⎥
  ⎥
  ⎦

  each component of this list is a solution, you have two solutions depending on the constant c_1 (y′(0)=c1) and corresponding to y(0)=1 and to y(0)=−1.
- Solve:

  y″+y=cos(x), (y(0))2=1 y′(0)=1

  Input:
  desolve([y’’+y=cos(x),y(0)^2=1,y’(0)=1],y)
  Output:

  ⎡
  ⎢
  ⎢
  ⎣

  3 cosx
  4

  +sinx+

  2 x sinx+cosx
  4

  ,−

  5 cosx
  4

  +sinx+

  2 x sinx+cosx
  4

  ⎤
  ⎥
  ⎥
  ⎦

  each component of this list is a solution (you have two solutions).
- Solve:

  y″+2y′+y=0

  Input:
  desolve(y’’+2*y’+y=0,y)
  Output:

  e−x | ⎛ ⎝ | c0 x+c1 | ⎞ ⎠

  the solution depends on two constants of integration: c_0 and c_1 (y(0)=c_0 and y′(0)=c_1).
- Solve:

  y″−6y′+9y=xe3x

  Input:
  desolve(y’’-6*y’+9*y=x*exp(3*x),y)
  Output:

  e3 x

  ⎛
  ⎝

  c0 x+c1

  ⎞
  ⎠

  +

  1
  6

  x3 e3 x

  The solution depends on 2 constants of integration: c_0, c_1 (y(0)=c_0 and y′(0)=c_1).

- Examples of first order linear equations.
  - Solve:

    xy′+y−3x2=0

    Input:
    desolve(x*y’+y-3*x^2,y)
    Output:

    c0+x3
    x

  - Solve:

    y′+x*y=0, y(0)=1

    Input:
    desolve([y’+x*y=0, y(0)=1]),y)
    or:
    desolve((y’+x*y=0) && (y(0)=1),y)
    Output:

    e

    −

    x2
    2

  - Solve:

    x(x2−1)y′+2y=0

    Input:
    desolve(x*(x^2-1)*y’+2*y=0,y)
    Output:

    c0 x2
    x2−1

  - Solve:

    x(x2−1)y′+2y=x2

    Input:
    desolve(x*(x^2-1)*y’+2*y=x^2,y)
    Output:

    c0 x2+x2 lnx
    x2−1

  - If the variable is t instead of x, for example, solve:

    t(t2−1)y′(t)+2y(t)=t2

    Input:
    desolve(t*(t^2-1)*diff(y(t),t)+2*y(t)=(t^2),y(t))
    Output:

    c0 t2+t2 lnt
    t2−1

  - Solve:

    x(x2−1)y′+2y=x2,y(2)=0

    Input:
    desolve([x*(x^2-1)*y’+2*y=x^2,y(2)=0],y)
    Output:

    −ln | ⎛ ⎝ | 2 | ⎞ ⎠ | x2+x2 lnx

    x2−1

  - Solve:

    √

    1+x2

    y′−x−y=

    √

    1+x2

    Input:
    desolve(y’*sqrt(1+x^2)-x-y-sqrt(1+x^2),y)
    Output:

    −c0+ln

    ⎛
    ⎜
    ⎝

    √

    x2+1

    −x

    ⎞
    ⎟
    ⎠

    x−

    √

    x2+1

- Examples of first differential equations with separable variables.
  - Solve:

    y′=2

    √

    y

    Input:
    desolve(y’=2*sqrt(y),y)
    Output:

    ⎡
    ⎢
    ⎢
    ⎢
    ⎢
    ⎢
    ⎣

    ⎛
    ⎜
    ⎜
    ⎝

    −

    1
    2

    c0+x

    ⎞
    ⎟
    ⎟
    ⎠

    2

    ⎤
    ⎥
    ⎥
    ⎥
    ⎥
    ⎥
    ⎦

  - Solve:

    xy′ln(x)−y(3ln(x)+1)=0

    Input:
    desolve(x*y’*ln(x)-(3*ln(x)+1)*y,y)
    Output:

    c0 x3 lnx

- Examples of Bernoulli differential equations a(x)y′+b(x)y=c(x)yn where n is a real constant.
  The method used is to divide the equation by yn, so that it becomes a first order linear differential equation in u=1/yn−1.
  - Solve:

    xy′+2y+xy2=0

    Input:
    desolve(x*y’+2*y+x*y^2,y)
    Output:

    ⎡
    ⎢
    ⎢
    ⎣

    0,−

    1
    c1 x2+x

    ⎤
    ⎥
    ⎥
    ⎦

  - Solve:

    xy′−2y=xy3

    Input:
    desolve(x*y’-2*y-x*y^3,y)
    Output:

    ⎡
    ⎢
    ⎢
    ⎢
    ⎢
    ⎢
    ⎣

    ⎛
    ⎜
    ⎜
    ⎝

    ⎛
    ⎜
    ⎜
    ⎝

    −

    1
    5

    · 2 x5+c0

    ⎞
    ⎟
    ⎟
    ⎠

    e−4 lnx

    ⎞
    ⎟
    ⎟
    ⎠

    −

    1
    2

    ,−

    ⎛
    ⎜
    ⎜
    ⎝

    ⎛
    ⎜
    ⎜
    ⎝

    −

    1
    5

    · 2 x5+c0

    ⎞
    ⎟
    ⎟
    ⎠

    e−4 lnx

    ⎞
    ⎟
    ⎟
    ⎠

    −

    1
    2

    ⎤
    ⎥
    ⎥
    ⎥
    ⎥
    ⎥
    ⎦

  - Solve:

    x2y′−2y=xe(4/x)y3

    Input:
    desolve(x*y’-2*y-x*exp(4/x)*y^3,y)
    Output:

    ⎡
    ⎢
    ⎢
    ⎢
    ⎢
    ⎢
    ⎢
    ⎢
    ⎣

    ⎛
    ⎜
    ⎜
    ⎜
    ⎜
    ⎝

    ⎛
    ⎜
    ⎜
    ⎜
    ⎜
    ⎝

    −

    ∫

    2 x4

    ⎛
    ⎜
    ⎝

    e

    1
    x

    ⎞
    ⎟
    ⎠

    4

    dx+c0

    ⎞
    ⎟
    ⎟
    ⎟
    ⎟
    ⎠

    e−4 lnx

    ⎞
    ⎟
    ⎟
    ⎟
    ⎟
    ⎠

    −

    1
    2

    ,−

    ⎛
    ⎜
    ⎜
    ⎜
    ⎜
    ⎝

    ⎛
    ⎜
    ⎜
    ⎜
    ⎜
    ⎝

    −

    ∫

    2 x4

    ⎛
    ⎜
    ⎝

    e

    1
    x

    ⎞
    ⎟
    ⎠

    4

    dx+c0

    ⎞
    ⎟
    ⎟
    ⎟
    ⎟
    ⎠

    e−4 lnx

    ⎞
    ⎟
    ⎟
    ⎟
    ⎟
    ⎠

    −

    1
    2

    ⎤
    ⎥
    ⎥
    ⎥
    ⎥
    ⎥
    ⎥
    ⎥
    ⎦

- Examples of first order homogeneous differential equations (y′=F(y/x), the method of integration is to search for t=y/x instead of y).
  - Solve:

    3x3y′=y(3x2−y2)

    Input:
    desolve(3*x^3*diff(y)=((3*x^2-y^2)*y),y)
    Output:

    ⎡
    ⎢
    ⎢
    ⎢
    ⎢
    ⎢
    ⎣

    0,−

    x

    √

    6

    √

    ln

    ⎛
    ⎜
    ⎜
    ⎝

    x
    c0

    ⎞
    ⎟
    ⎟
    ⎠

    2 ln

    ⎛
    ⎜
    ⎜
    ⎝

    x
    c0

    ⎞
    ⎟
    ⎟
    ⎠

    ,

    x

    √

    6

    √

    ln

    ⎛
    ⎜
    ⎜
    ⎝

    x
    c0

    ⎞
    ⎟
    ⎟
    ⎠

    2 ln

    ⎛
    ⎜
    ⎜
    ⎝

    x
    c0

    ⎞
    ⎟
    ⎟
    ⎠

    ⎤
    ⎥
    ⎥
    ⎥
    ⎥
    ⎥
    ⎦

    Hence the solutions are y=0 and the familiy of curves with parametric equations x=c0exp(3/(2t2)), y=t*c0exp(3/(2t2)) (the parameter is denoted by ‘ t‘ in the answer).
- Examples of first order differential equations with an integrating factor. By multiplying the equation by a function of x,y, it becomes a closed differential form.
  - Solve:

    yy′+x=0

    Input:
    desolve(y*y’+x,y)
    Output:

    ⎡
    ⎢
    ⎣

    √

    −x2−2 c0

    ,−

    √

    −x2−2 c0

    ⎤
    ⎥
    ⎦

    In this example, xdx+ydy is closed, the integrating factor was 1.
  - Solve:

    2xyy′+x2−y2+a2=0

    Input:
    desolve(2*x*y*y’+x^2-y^2+a^2,y)
    Output:

    ⎡
    ⎢
    ⎣

    √

    a2−x2−c1 x

    ,−

    √

    a2−x2−c1 x

    ⎤
    ⎥
    ⎦

    In this example, the integrating factor was 1/x2.
- Example of first order differential equations without x.
  Solve:

  (y+y′)4+y′+3y=0

  This kind of equation cannot be solved directly by Xcas, you can use the following steps on solve it with the help of Xcas. The idea is to find a parametric representation of F(u,v)=0 where the equation is F(y,y′)=0. Let u=f(t),v=g(t) be such a parametrization of F=0, then y=f(t) and dy/dx=y′=g(t). Hence

  dy/dt=f′(t)=y′*dx/dt=g(t)*dx/dt

  The solution is the curve of parametric equations x(t), y(t)=f(t), where x(t) is solution of the differential equation g(t)dx=f′(t)dt.
  Back to the example, you can let y+y′=t, hence:

  y=−t−8*t4, y′=dy/dx=3*t+8*t4 dy/dt=−1−32*t3

  therefore

  (3*t+8*t4)*dx=(−1−32*t3)dt

  Input:
  desolve((3*t+8*t^4)*diff(x(t),t)=(-1-32*t^3),x(t))
  Output:

  9 c0−11 ln | ⎛ ⎝ | 8 t3+3 | ⎞ ⎠ | −ln | ⎛ ⎝ | t3 | ⎞ ⎠

  9

  The solution is the curve of parametric equation:

  x(t)=−11*1/9*ln(8*t3+3)+1/−9*ln(t3)+c0, y(t)=−t−8*t4

- Examples of first order Clairaut differential equations (y=x*y′+f(y′)).
  The solutions are the lines Dm of equation y=mx+f(m) where m is a real constant.
  - Solve:

    xy′+y′3−y=0

    Input:
    desolve(x*y’+y’^3-y,y)
    Output:

    ⎡ ⎣ | c0 x+c03 | ⎤ ⎦

  - Solve:

    y−xy′ −

    √

    a2+b2*y′2

    =0

    Input:
    desolve((y-x*y’-sqrt(a^2+b^2*y’^2),y)
    Output:

    ⎡
    ⎢
    ⎣

    c0 x+

    √

    a2+b2 c02

    ⎤
    ⎥
    ⎦