Skip to main content
Back to module
Calculus & Linear Algebra for STEM · Integrals

Intro to differential equations

Reading52mLesson 3 of 3 in this module

Model growth and decay with dy/dt = ky, and simulate equations step by step with Euler's method.

Why this matters

Many laws of nature are stated as rates. A radioactive sample decays at a rate proportional to how much is left. A cup of coffee cools at a rate proportional to its temperature difference with the room. A population grows in proportion to its size until resources run out. Equations that relate a quantity to its own rate of change are differential equations, and they are the language of physics, chemistry, epidemiology, finance and control engineering.

The core idea

A differential equation gives a rule for the derivative. The simplest important one is:

dy/dt = k · y

"The rate of change of y is proportional to y." Its solution is exponential:

y(t) = y₀ · e^(kt)

You can check it: the derivative of y₀e^(kt) is k · y₀e^(kt) = k · y. With k > 0 it describes growth (compound interest, bacteria); with k < 0 it describes decay (radioactivity, drug elimination, a capacitor discharging).

Worked example: a drug is eliminated at 30% of the current amount per hour (k = −0.3) and the starting dose is 200 mg. After 4 hours: y = 200 · e^(−1.2) ≈ 60.2 mg. The half-life is ln 2 / 0.3 ≈ 2.31 hours.

Initial conditions

A differential equation alone describes a family of curves. The initial condition (y₀ at t = 0) picks the one that matches your situation, just as the + C in an indefinite integral is fixed by a known value.

When there is no formula: Euler's method

Most real models, such as the logistic growth equation dy/dt = r·y·(1 − y/K), predator-prey systems or a pendulum with friction, are solved numerically. Euler's method is the simplest approach and the idea behind every solver:

  1. Start at (t₀, y₀).
  2. The equation tells you the slope there: f(t₀, y₀).
  3. Take a small step of size h along that slope: y₁ = y₀ + h · f(t₀, y₀), t₁ = t₀ + h.
  4. Repeat from the new point.
def euler(f, y0, t0, t1, n):
    h = (t1 - t0) / n
    t, y = t0, y0
    for _ in range(n):
        y = y + h * f(t, y)
        t = t + h
    return y

decay = lambda t, y: -0.3 * y
print(euler(decay, 200, 0, 4, 1000))   # about 60.2, close to 200 * e^(-1.2)

Worked by hand with only two steps (h = 2): y₁ = 200 + 2 · (−60) = 80, then y₂ = 80 + 2 · (−24) = 32. That is far from 60.2. Euler's method is only accurate when the steps are small, because it follows a straight line while the true curve bends.

Professional solvers

In practice you would call a library: scipy.integrate.solve_ivp uses Runge-Kutta methods, which sample the slope several times per step for much better accuracy, and adapts the step size automatically. MATLAB's ode45 is the same family. Knowing Euler's method tells you what these tools are doing and why step size matters.

Common mistakes

  • Steps that are too large. Halve h and compare. If the answer changes a lot, the step is too big. With large steps a decay model can even oscillate or blow up.
  • Mixing up the rate constant's sign. Decay needs k < 0 in dy/dt = ky (or write −k with k > 0).
  • Forgetting units. If t is in hours, k is per hour.
  • Ignoring the initial condition. Without y₀ there is no unique answer.

Quick recap

  • A differential equation relates a quantity to its rate of change.
  • dy/dt = ky has the exponential solution y₀e^(kt): growth for k > 0, decay for k < 0.
  • Euler's method steps along the slope: y ← y + h · f(t, y).
  • Smaller steps are more accurate; professional solvers use smarter, adaptive methods.

Try it

In the Do tab, write the Euler update and simulate decay and growth.

Also in this lesson: