Skip to content
Tutorials Center
My learning

Topics

Lesson 33 of 39 · Introduction to Differential Equations

Separable Differential Equations

Solve first-order separable differential equations by separating variables and integrating both sides, with initial values, examples and code checks.

Some differential equations can be solved with a neat trick: get all the y terms on one side with dy, all the x terms on the other side with dx, and integrate both sides. Such equations are called separable, and they are the first kind you should learn to solve.

What is separable?

A first-order equation is separable if it can be written as

Text
dy/dx = g(x) · h(y)

That is, the right side is a product of a function of x alone and a function of y alone. For example dy/dx = 2xy is separable, but dy/dx = x + y is not (it is a sum, and cannot be factored that way).

The method

  1. Write dy/dx = g(x) h(y).
  2. Separate the variables: divide by h(y) and multiply by dx, so that dy / h(y) = g(x) dx. (If h(y) = 0 for some y, that constant y is also a solution: check it separately.)
  3. Integrate both sides: ∫ dy/h(y) = ∫ g(x) dx. Put one constant C on one side only.
  4. Solve for y if possible.
  5. Use the initial condition to find C.

Treating dy and dx like separate quantities is shorthand. It is justified by the chain rule and substitution, and it works well in practice.

Example 1: dy/dx = 2xy

Separate: dy/y = 2x dx. Integrate: ln(abs(y)) = x² + C. Exponentiate: abs(y) = e^(x² + C) = e^C · e^(x²). The constant e^C is positive, but we can absorb a sign into a new constant A (which can be positive, negative, or even zero for the solution y = 0):

Text
y = A e^(x²)

With y(0) = 3, we get A = 3, so y = 3e^(x²).

Example 2: dy/dx = x/y

Separate: y dy = x dx. Integrate: y²/2 = x²/2 + C, or y² - x² = K where K = 2C. The solutions are hyperbolas. With y(0) = 2, K = 4, so y² = x² + 4, and since y(0) = 2 is positive we take y = √(x² + 4).

Notice we left the answer in a form with y solved for explicitly, which matches the initial condition's sign. When you cannot solve for y, an implicit solution such as y² - x² = 4 is perfectly fine.

Example 3: cooling

Newton's law of cooling says an object's temperature changes at a rate proportional to the difference from the surroundings. Let T be the temperature of a cup of tea in a room at 20 °C: dT/dt = -k (T - 20). Separate: dT/(T - 20) = -k dt. Integrate: ln(abs(T - 20)) = -kt + C, so T - 20 = A e^(-kt). If the tea starts at 90 °C, then A = 70, and

Text
T(t) = 20 + 70 e^(-kt)

The temperature decays toward 20 °C. If after 10 minutes the tea has cooled to 60 °C, then 40 = 70 e^(-10k), giving k = ln(70/40)/10 ≈ 0.0560 per minute.

Python Solve separable equations with sympy

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Checking a result numerically

A solution should satisfy the original equation at every point. We can verify with a numeric derivative: compare the slope of our y(x) with the right-hand side of the equation.

Python Check dy/dx = 2xy against y = 3 e^(x^2)

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Pitfalls

  • Constant solutions. When you divide by h(y), you may lose solutions where h(y) = 0. For dy/dx = y(1 - y) the constants y = 0 and y = 1 are solutions you must list yourself.
  • One constant is enough. Do not write a constant on both sides.
  • Domain issues. ln(abs(y)) needs y ≠ 0. Remember to treat the sign carefully when removing the logarithm.
  • Not every equation is separable. If you cannot factor the right side into g(x)h(y), other methods (such as integrating factors) are needed.

A solution is valid only on an interval where it is defined and differentiable. For dy/dx = y² with y(0) = 1, the solution y = 1/(1 - x) exists only for x < 1: it blows up in finite time.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. Which equation is separable?

    x · y² is a product of a function of x and a function of y.
  2. 2. Separating variables in dy/dx = 2xy gives

    Divide both sides by y and multiply by dx.
  3. 3. The general solution of dy/dx = ky is

    Separate: dy/y = k dx, so ln(abs(y)) = kx + C, giving y = A e^(kx).
  4. 4. For dy/dx = x/y with y(0) = 2, which relation holds?

    From y² - x² = K and y(0) = 2 we get K = 4.

Summary

  • A separable equation has the form dy/dx = g(x) h(y).
  • Separate, integrate both sides, add a single constant, solve for y, and apply the initial condition.
  • Check for constant solutions where h(y) = 0.
  • Cooling, growth and decay are all separable.

Next: Euler's Method