Method on @sym: sol = dsolve (ode)
Method on @sym: sol = dsolve (ode, IC)
Method on @sym: sol = dsolve (ODEs, IC1, IC2, …)
Method on @sym: sol = dsolve (ODEs, ICs)
Method on @sym: [sol, classify] = dsolve (…)

Solve ordinary differential equations (ODEs) symbolically.

Basic example:

syms y(x)
DE = diff(y, x) - 4*y == 0
  ⇒ DE = (sym)
                d
      -4⋅y(x) + ──(y(x)) = 0
                dx

sol = dsolve (DE)
  ⇒ sol = (sym)
          4⋅x
      C₁⋅ℯ

You can specify initial conditions:

sol = dsolve (DE, y(0) == 1)
  ⇒ sol = (sym)
       4⋅x
      ℯ

In some cases, SymPy can return a classification of the differential equation:

DE = diff(y) == y^2
  ⇒ DE = (sym)
      d           2
      ──(y(x)) = y (x)
      dx

[sol, classify] = dsolve (DE, y(0) == 1)
  ⇒ sol = (sym)
       -1
      ─────
      x - 1
  ⇒ classify = ... separable ...

Many types of ODEs can be solved, including initial-value problems and boundary-value problem:

DE = diff(y, 2) == -9*y
  ⇒ DE = (sym)
         2
        d
       ───(y(x)) = -9⋅y(x)
         2
       dx

dsolve (DE, y(0) == 1, diff(y)(0) == 12)
  ⇒ (sym) 4⋅sin(3⋅x) + cos(3⋅x)

dsolve (DE, y(0) == 1, y(sym(pi)/2) == 2)
  ⇒ (sym) -2⋅sin(3⋅x) + cos(3⋅x)

Some systems can be solved, including initial-value problems involving linear systems of first order ODEs with constant coefficients:

syms x(t) y(t)
ode_sys = [diff(x(t),t) == 2*y(t);  diff(y(t),t) == 2*x(t)]
  ⇒ ode_sys = (sym 2×1 matrix)
      ⎡d                ⎤
      ⎢──(x(t)) = 2⋅y(t)⎥
      ⎢dt               ⎥
      ⎢                 ⎥
      ⎢d                ⎥
      ⎢──(y(t)) = 2⋅x(t)⎥
      ⎣dt               ⎦

soln = dsolve (ode_sys)
  ⇒ soln = scalar structure containing ...
       x = ...
       y = ...

soln.x
  ⇒ ans =
      (sym)
              -2⋅t       2⋅t
        - C₁⋅ℯ     + C₂⋅ℯ

soln.y
  ⇒ ans =
      (sym)
            -2⋅t       2⋅t
        C₁⋅ℯ     + C₂⋅ℯ

Note: The Symbolic Math Toolbox used to support strings like ’Dy + y = 0’; we are unlikely to support this so you will need to assemble a symbolic equation instead.

See also: @sym/diff, @sym/int, @sym/solve.

Package: symbolic