differential equations25 min

Separable Equations

Separable ODEs where variables can be split to opposite sides and integrated independently

0/9Not Started

Why This Matters

Not every ODE needs a computer to solve it. A separable equation is a first-order ODE where you can move all the y terms to one side and all the x terms to the other. Once separated, you integrate both sides independently -- turning a differential equation into two ordinary integrals.

The technique of separation of variables is one of the most powerful analytical methods in mathematics. It gives you a general solution -- a family of curves described by a formula with an arbitrary constant. Plugging in an initial condition pins down that constant and gives the unique solution. This method works for exponential growth, radioactive decay, Newton law of cooling, and many other models that appear across science.

Define Terms

Visual Model

dy/dx = g(x) * h(y)Separable form
dy / h(y) = g(x) dxVariables separated
Integrate leftintegral of 1/h(y) dy
Integrate rightintegral of g(x) dx
General SolutionH(y) = G(x) + C
Apply Initial ConditionSolve for C
Particular SolutionUnique curve

The full process at a glance. Click Start tour to walk through each step.

Separation of variables: split the ODE, integrate both sides, then use the initial condition to find the unique solution.

Code Example

Code
// Separable ODE: dy/dx = 2x * y, y(0) = 1
// Separation: dy/y = 2x dx
// Integrate: ln|y| = x^2 + C
// Exact solution: y = e^(x^2) (with y(0) = 1, C = 0)

// Verify: compute derivative of solution and check it equals 2x * y
function verifySolution(x) {
  const y = Math.exp(x * x);         // proposed solution
  const dydx_from_ode = 2 * x * y;   // right side of ODE

  // Compute derivative numerically
  const h = 0.0001;
  const yPlus = Math.exp((x + h) * (x + h));
  const dydx_numerical = (yPlus - y) / h;

  return {
    x,
    y: Math.round(y * 1000) / 1000,
    dydx_ode: Math.round(dydx_from_ode * 1000) / 1000,
    dydx_numerical: Math.round(dydx_numerical * 1000) / 1000
  };
}

console.log("Verifying y = e^(x^2) solves dy/dx = 2xy:");
[0, 0.5, 1.0, 1.5].forEach(x => {
  const v = verifySolution(x);
  console.log(`  x=${v.x}: y=${v.y}, ODE=${v.dydx_ode}, numerical=${v.dydx_numerical}`);
});

// General solution family: y = C * e^(x^2)
console.log("\nSolution family for different initial values:");
[0.5, 1, 2, 5].forEach(c => {
  const yAt1 = c * Math.exp(1);
  console.log(`  C=${c}: y(0)=${c}, y(1)=${Math.round(yAt1 * 1000) / 1000}`);
});

// Another example: dy/dx = x / y, y(0) = 2
// Separation: y dy = x dx -> y^2/2 = x^2/2 + C -> y = sqrt(x^2 + 4)
console.log("\nVerifying y = sqrt(x^2 + 4) solves dy/dx = x/y:");
[0, 1, 2].forEach(x => {
  const y = Math.sqrt(x * x + 4);
  const dydx_ode = x / y;
  const h = 0.0001;
  const yPlus = Math.sqrt((x + h) * (x + h) + 4);
  const dydx_num = (yPlus - y) / h;
  console.log(`  x=${x}: ode=${Math.round(dydx_ode * 1000) / 1000}, num=${Math.round(dydx_num * 1000) / 1000}`);
});

Interactive Experiment

Try these exercises:

  • For dy/dx = 3x^2 * y with y(0) = 2, separate variables and find the general solution. Then verify it with code by computing both sides of the equation.
  • Solve dy/dx = -y (exponential decay) by separation. What is the general solution? How does the constant C relate to the initial value?
  • Try to separate dy/dx = x + y. Can you factor the right side into g(x) * h(y)? Why not?
  • For dy/dx = x / y, what happens at y = 0? Why does this matter for the separable method?
  • Compare the exact solution of dy/dx = y with the Euler method approximation from the previous lesson. How close is the numerical answer?

Quick Quiz

Coding Challenge

Solution Verifier

Write a function called `verifySeparable` that checks whether a proposed solution y(x) satisfies an ODE dy/dx = f(x, y). It should take three arguments: a solution function sol(x), the ODE right-hand side f(x, y), and a test point x. Use a small h = 0.0001 to compute the numerical derivative as (sol(x+h) - sol(x)) / h, then compare with f(x, sol(x)). Return true if the difference is less than 0.01, false otherwise.

Loading editor...

Real-World Usage

Separable equations model many natural phenomena:

  • Radioactive decay: dN/dt = -lambda * N is separable. The solution N = N0 * e^(-lambda*t) predicts how much material remains after time t. This is the basis for carbon dating.
  • Newton law of cooling: dT/dt = -k(T - Tenv) is separable after substitution. It models how a hot coffee cools toward room temperature.
  • Population growth: The logistic equation dP/dt = rP(1 - P/K) is separable and models growth with a carrying capacity K.
  • Chemical reactions: First-order reaction kinetics follow dC/dt = -kC, giving exponential concentration decay.
  • Electrical circuits: A simple RC circuit follows dV/dt = -V/(RC), which is separable and gives exponential voltage decay.

Connections