TExcelTAD
Home › Differential Equations › First-Order Models: Mixing, Cooling, Interest

First-Order Models: Mixing, Cooling, Interest

Most first-order models come from one principle:

rate of change=rate in−rate out.\text{rate of change} = \text{rate in} - \text{rate out}.

This lesson builds three classic models from it, solves them with the methods of this chapter and checks them numerically. Each is a template for many others.

Mixing tanks

A tank holds 100 L of water with 5 kg of salt dissolved. Brine with 0.2 kg/L flows in at 3 L/min, and the well-stirred mixture flows out at 3 L/min. Let x(t)x(t) be the salt in kg.

  • Rate in: 0.2⋅3=0.60.2 \cdot 3 = 0.6 kg/min.
  • Rate out: concentration times outflow, x100⋅3\frac{x}{100} \cdot 3.
x′=0.6−0.03x,x(0)=5.x' = 0.6 - 0.03x, \qquad x(0) = 5.

This is linear with equilibrium x=20x = 20 kg (the inflow concentration times the volume), and the solution is x(t)=20−15e−0.03tx(t) = 20 - 15e^{-0.03t}.

If the outflow differs from the inflow, the volume changes, V(t)=V0+(rin−rout)tV(t) = V_0 + (r_{\text{in}} - r_{\text{out}})t, and the equation gets a variable coefficient:

python · try it yourself
import sympy as sp

t = sp.symbols("t", nonnegative=True)
x = sp.Function("x")
V = 100 + (3 - 2) * t                     # in 3 L/min, out 2 L/min
ode = sp.Eq(x(t).diff(t), sp.Rational(6, 10) - 2 * x(t) / V)
sol = sp.dsolve(ode, ics={x(0): 5}).rhs
print("x(t) =", sp.simplify(sol))
print("salt after 60 min:", round(float(sol.subs(t, 60)), 4), "kg in", 100 + 60, "L")
x(t) = (t**3 + 300*t**2 + 30000*t + 250000)/(5*(t**2 + 200*t + 10000))
salt after 60 min: 26.1406 kg in 160 L

Newton's law of cooling

An object's temperature changes at a rate proportional to its difference from the surroundings: T′=−k(T−Ta)T' = -k(T - T_a). The solution is T(t)=Ta+(T0−Ta)e−ktT(t) = T_a + (T_0 - T_a)e^{-kt}. Two measurements determine kk.

Example. A pie comes out of the oven at 180 °C into a 20 °C kitchen and is 120 °C after 10 minutes. Then 100=160e−10k100 = 160e^{-10k}, k=ln⁡1.610k = \frac{\ln 1.6}{10}. When is it 40 °C?

python · try it yourself
import math

Ta, T0 = 20.0, 180.0
k = math.log(160 / 100) / 10
t40 = math.log((T0 - Ta) / (40 - Ta)) / k
print(f"k = {k:.5f} per minute, 40 degrees after {t40:.1f} minutes")
k = 0.04700 per minute, 40 degrees after 44.2 minutes

Continuous interest with deposits

A balance BB grows at rate rr and receives continuous deposits of dd per year: B′=rB+dB' = rB + d. With B(0)=B0B(0) = B_0:

B(t)=(B0+dr)ert−dr.B(t) = \left(B_0 + \frac{d}{r}\right)e^{rt} - \frac{d}{r}.

For a loan, dd is negative (payments). The loan is paid off when B=0B = 0; payments must exceed rB0rB_0 or the debt grows forever (the equilibrium B=−d/rB = -d/r is unstable).

python · try it yourself
import numpy as np
from scipy.integrate import solve_ivp

r, d, B0 = 0.05, -12_000.0, 150_000.0        # 5 % loan, 12,000 per year in payments
paid = lambda t, B: B[0]
paid.terminal = True
sol = solve_ivp(lambda t, B: r * B + d, (0, 100), [B0], events=paid, rtol=1e-10, atol=1e-6)
T_exact = np.log((d / r) / (B0 + d / r)) / r
print(f"paid off after {sol.t_events[0][0]:.3f} years (formula {T_exact:.3f})")
print(f"total paid: {-d * T_exact:,.0f}")
paid off after 19.617 years (formula 19.617)
total paid: 235,399

Checklist for building a model

  1. Name the unknown and its units.
  2. Write rate in and rate out; check that the units of every term match.
  3. Identify the equilibrium and whether it is stable (it is often the physically obvious long-run value).
  4. Solve, then sanity-check limits: t=0t = 0 and t→∞t \to \infty.

In software

  • Compartment models (drug dosing in pharmacology, inventory and queue models, the SIR model) are systems of "in minus out" equations.
  • Thermal throttling in CPUs and GPUs uses exactly the cooling model: the chip's temperature relaxes toward a target set by power draw, and controllers predict it with T′=−k(T−Ta)+cPT' = -k(T - T_a) + cP.

Exercises

Exercise 1: Mixing equilibrium

A 50 L tank of pure water receives brine of 0.1 kg/L at 2 L/min and drains at 2 L/min. How much salt is there after a long time, and after 25 minutes?

Answer

5 kg in the long run; 5(1−e−1)≈3.165(1 - e^{-1}) \approx 3.16 kg at 25 minutes.

Solution

x′=0.2−2x50=0.2−0.04xx' = 0.2 - \frac{2x}{50} = 0.2 - 0.04x, x(0)=0x(0) = 0, so x=5(1−e−0.04t)x = 5(1 - e^{-0.04t}). At t=25t = 25: 5(1−e−1)5(1 - e^{-1}).

Exercise 2: Cooling constant

A drink at 4 °C warms to 10 °C after 30 minutes in a 25 °C room. Find kk.

Answer

k=130ln⁡2115≈0.0112k = \frac{1}{30}\ln\frac{21}{15} \approx 0.0112 per minute.

Solution

T−25=−21e−ktT - 25 = -21e^{-kt}; at 30 minutes, −15=−21e−30k-15 = -21e^{-30k}, so e−30k=1521e^{-30k} = \frac{15}{21} and k=ln⁡1.430k = \frac{\ln 1.4}{30}.

Exercise 3: Minimum payment (code)

For the loan in the lesson, what is the smallest yearly payment that ever pays it off? How long does 15,000 per year take?

Answer

More than 7,500 per year; about 13.86 years at 15,000.

Solution

The balance falls only if rB0+d<0rB_0 + d < 0, i.e. payments above 0.05⋅150,000=7,5000.05 \cdot 150{,}000 = 7{,}500. With d=−15,000d = -15{,}000: T=1rln⁡−d/r−d/r−B0=20ln⁡2T = \frac{1}{r}\ln\frac{-d/r}{-d/r - B_0} = 20\ln 2.

python · try it yourself
import math
r, d, B0 = 0.05, -15_000.0, 150_000.0
print(round(math.log((d / r) / (B0 + d / r)) / r, 2), round(20 * math.log(2), 2))
13.86 13.86

Test yourself

In a well-stirred tank of volume VV with outflow rate rr, the salt leaves at rate…

  1. rr
  2. xVr\frac{x}{V}r
  3. xVxV
  4. Vx\frac{V}{x}

In Newton's law of cooling T′=−k(T−Ta)T' = -k(T - T_a), the long-run temperature is…

  1. 0
  2. T0T_0
  3. TaT_a
  4. it oscillates

For B′=rB+dB' = rB + d with r>0r > 0, the equilibrium B=−d/rB = -d/r is…

  1. stable
  2. unstable
  3. semistable
  4. not an equilibrium