Skip to content
Tutorials Center
My learning

Topics

Lesson 22 of 46 · Continuous Models with ODEs

Growth, decay and Euler's method

Model growth, decay and Newton's law of cooling with dy/dt = k·y, then learn Euler's method to solve any first-order ODE step by step on a computer.

Some things change at a speed proportional to how much of them there is. A bigger colony of bacteria produces more new bacteria per hour. A bigger dose of medicine in the blood is cleared faster. A hotter cup of coffee loses heat faster. This single idea gives the most useful ODE in science, dy/dt = k·y, and in this lesson you will solve it twice: once with a formula, and once with a few lines of code that work on almost any ODE.

A decay curve drawn exactly and approximated by Euler steps of size 1 and 0.25 with a card explaining one Euler step.
Euler's method walks along the slope. A smaller step size keeps the walk closer to the true curve.

What you will learn

  • How to turn "rate proportional to size" into dy/dt = k·y and solve it.
  • How to find half-life, doubling time and Newton's cooling curve.
  • How Euler's method builds a solution from the slope alone.
  • Why a smaller step size gives a smaller error.

Key terms

Rate constant (k): the number that says how strongly the current size drives the change. Its unit is 1 per unit of time.

Half-life: the time for a decaying quantity to fall to half its value.

Step size (h): the time jump used by a numerical method.

Euler's method: the rule y_new = y_old + h · f(t_old, y_old).

Exponential growth and decay

Suppose the population y of a bacterial colony grows at a rate proportional to its size: dy/dt = k·y with k > 0. Try the guess y = y₀·e^(k·t). Its derivative is k·y₀·e^(k·t), which is exactly k·y. At t = 0 it equals y₀, so it matches the starting value. That is the solution:

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

When k < 0 the same formula describes decay. A medicine with a half-life of 5 hours has e^(k·5) = 1/2, so k = −ln(2)/5 ≈ −0.139 per hour. Starting with 200 mg, after 10 hours (two half-lives) 50 mg remain. For growth, the doubling time is ln(2)/k: if k = 0.3 per hour the colony doubles every 2.31 hours.

Newton's law of cooling

A cup of coffee at 90 °C in a 20 °C room cools faster when the gap is large. The natural model is that the rate is proportional to the gap, not the temperature: dT/dt = −k·(T − T_room). Let u = T − T_room. Then du/dt = −k·u, the decay model again, so

T(t) = T_room + (T₀ − T_room) · e^(−k·t)

With k = 0.05 per minute: T(10) = 20 + 70·e^(−0.5) ≈ 62.5 °C. Notice that the temperature approaches 20 °C but never goes below it, which is physically sensible.

Euler's method: following the slope

Most ODEs have no formula-shaped solution, so we need a method that uses only the rule for the slope. Leonhard Euler's idea (1768) is as simple as walking on a hillside: stand at a point, look at the slope there, take a small step in that direction, then repeat.

For dy/dt = f(t, y) with y(t₀) = y₀:

y₁ = y₀ + h · f(t₀, y₀), then t₁ = t₀ + h, and so on.

Worked example. dy/dt = −0.5·y, y(0) = 10, step h = 1. The slope at the start is −0.5 × 10 = −5, so y(1) ≈ 10 − 5 = 5. The next slope is −2.5, so y(2) ≈ 2.5. The exact answer at t = 1 is 10·e^(−0.5) = 6.07. Euler undershoots, because the true curve flattens during the step while Euler uses the steep starting slope all the way.

Halve the step to h = 0.5: y(0.5) = 10 − 0.5×5 = 7.5, y(1) = 7.5 − 0.5×3.75 = 5.625. Closer to 6.07. Euler's method is first order: halving h roughly halves the final error. You will see this in the second demo below.

Python Euler against the exact curve

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.

Common misconceptions

"A smaller step is always better." Only until round-off error and computing time start to matter. For a smooth ODE, h = 0.001 is already far more precise than the data you could measure.

"Cooling is proportional to temperature." It is proportional to the temperature difference from the surroundings. A cup at room temperature does not cool at all.

"The Euler answer is exact if the ODE is linear." No. Euler has a built-in error even for the simplest ODE, as the table below shows.

How the error behaves

Run the next demo. It solves the decay problem at time t = 6 with several step sizes and prints the error. If the method is first order, each halving of h should roughly halve the error. Then it models the cooling coffee with SciPy's solver and uses the formula to answer "when does it reach 60 °C?" in two ways.

Python Error table and cooling coffee

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.

Explore the step size yourself

Drag the slider. Large steps give a jagged, inaccurate polyline. Small steps make it hug the curve.

Euler step-size slider

Check your understanding

Quick check · 5 questions

of 5 answered You scored / 5 · perfect!

  1. 1. A drug has a half-life of 5 hours. How much of a 200 mg dose remains after 10 hours?

    Ten hours is two half-lives, so the amount is halved twice: 200 to 100 to 50 mg.
  2. 2. Which ODE describes Newton's law of cooling for a body at temperature T in surroundings at T_room?

    The rate of cooling is proportional to the temperature difference between the object and its surroundings.
  3. 3. One Euler step for dy/dt = -0.5 y from y = 10 with h = 1 gives:

    y_new = 10 + 1 * (-0.5 * 10) = 5. The exact value 6.07 is higher, so the Euler step undershoots.
  4. 4. Euler's method is first order. What happens to the error when you halve the step size?

    First-order means the error is proportional to h, so halving h roughly halves the error.
  5. 5. A colony grows with k = 0.3 per hour. Its doubling time is about:

    Doubling time is ln(2)/k = 0.693/0.3 = 2.31 hours.

Summary

  • dy/dt = k·y has the solution y = y₀·e^(k·t): growth for k > 0, decay for k < 0.
  • Half-life is ln(2)/|k|; Newton's cooling is the same model applied to the gap T − T_room.
  • Euler's method: y_new = y_old + h·f(t_old, y_old). It only needs the slope rule.
  • Euler is first order, so halving h roughly halves the error.

Next: Logistic growth and harvesting