Skip to content
Tutorials Center
My learning

Topics

Lesson 4 of 39 ยท Getting Started

Modeling with Differential Equations

Turn real situations into ODEs: population growth, Newton's cooling, mixing tanks and falling objects. Learn the modeling recipe and check each model with Python.

Writing down a differential equation from a description is often harder than solving it. The reward is large, though: once a situation is an equation, everything in this course applies. This lesson gives a recipe and then four classic models, each solved and checked numerically.

The core idea is the balance law: rate of change = rate in - rate out. Whatever quantity Q(t) you care about (people, heat, salt, momentum), its derivative is what comes in per unit time minus what leaves. Almost every first-order model is a balance law with specific formulas for "in" and "out".

A modeling recipe

  1. Name the unknown and its units, for example P(t) = population in thousands, t in years.
  2. Choose the independent variable (usually time).
  3. Write the rate of change in words ("growth per year is proportional to the current population").
  4. Translate to symbols and introduce parameters (k, r, ...), with units.
  5. Add initial conditions.
  6. Solve, then sanity-check: signs, units, limiting cases.

Model 1: exponential growth and decay

If the rate of change is proportional to the current amount, dP/dt = k*P, the solution is P(t) = P0*e**(k*t). With k > 0 it describes unlimited growth (bacteria with plenty of food, money with continuous compounding), with k < 0 decay (radioactive material). The half-life is T = ln(2)/|k|.

Python Radioactive decay and half-life

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.

Model 2: Newton's law of cooling

An object at temperature T in a room at constant temperature A changes temperature at a rate proportional to the difference: dT/dt = -k*(T - A) with k > 0. The solution is T(t) = A + (T0 - A)*e**(-k*t): the object approaches room temperature exponentially, never overshooting. Cooling is why hot coffee drops quickly at first and slowly later.

Python 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.

Model 3: mixing tanks

A tank holds V liters of brine. Salt solution of concentration c_in (g/L) flows in at r L/min, and the well-stirred mixture flows out at the same rate. Let x(t) be the grams of salt. Then

dx/dt = r*c_in - r*x/V.

(In: concentration times flow. Out: current concentration x/V times flow.) This is a linear equation with the equilibrium x = V*c_in: eventually the tank has the inflow concentration. If the inflow and outflow rates differ, V itself changes with time and the equation gains a variable coefficient, which is solved with an integrating factor.

Mixing tank balance

Salt in flow rate times inflow concentration
Well stirred concentration is x / V everywhere
Salt out flow rate times x / V

dx/dt = in - out

1 / 2

Model 4: falling with air resistance

Newton's second law: m*dv/dt = m*g - c*v when drag is proportional to speed. The speed increases from v(0) = 0 and levels off at the terminal velocity v_t = m*g/c, where gravity and drag balance. Setting dv/dt = 0 gives v_t immediately, with no solving: this "find the equilibrium first" habit is powerful and reappears in autonomous equations. The solution is v(t) = v_t*(1 - e**(-c*t/m)).

Python Terminal velocity

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 model

  • Units: every term in the equation must have the same units. In dT/dt = -k*(T - A) the left side is degrees per minute, so k is per minute.
  • Limits: does the equilibrium make physical sense? A tank cannot hold negative salt.
  • Signs: is the solution moving in the direction your intuition says?
  • Reality: exponential growth cannot continue forever; the next models add limits (see the logistic equation in autonomous equations).

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A model says dP/dt = 0.03*P. What happens to P?

    A positive proportionality constant means the rate of change is positive and proportional to P, giving P = P0*e**(0.03 t).
  2. 2. In Newton's law of cooling dT/dt = -k(T - A), what does T approach?

    The rate is zero when T = A, and T moves toward A from either side.
  3. 3. For a mixing tank, the 'salt out' rate is

    Well-stirred means the outgoing concentration is x/V, so salt leaves at outflow rate times x/V.
  4. 4. How do you find terminal velocity quickest?

    At terminal velocity the acceleration is zero, so g - (c/m) v = 0 gives v = m g / c directly.

Summary

  • Most models are balance laws: rate of change = rate in - rate out.
  • Exponential growth/decay, Newton cooling, mixing and drag are the four classic first-order models.
  • Equilibria come from setting the derivative to zero, before solving anything.
  • Always check units, signs and limiting behavior.
  • scipy.integrate.solve_ivp solves any of these numerically and lets you verify your formulas.

Next: Separable Equations