TExcelTAD
Home › Calculus in Depth › Applications to Economics and Biology

Applications to Economics and Biology

The same "slice, approximate, add up, take the limit" recipe that gives areas and volumes also measures money and blood. This lesson computes consumer and producer surplus, the present value of an income stream, blood flow through a vessel (Poiseuille's law) and cardiac output from a dye test, and then uses a Lorenz curve integral to compute the Gini coefficient that data teams report.

Consumer and producer surplus

A demand function p(x)p(x) gives the price at which buyers will take xx units; it decreases. Split [0,X][0, X] into small batches: the buyers of the batch near xx would have paid p(x)p(x), but at the market price P=p(X)P = p(X) they pay only PP. Their saving is (p(x)−P) Δx(p(x) - P)\,\Delta x, and the total saving is the consumer surplus

CS=∫0X(p(x)−P) dx(area between the demand curve and the price line)CS = \int_0^X (p(x) - P)\,dx \qquad (\text{area between the demand curve and the price line})

Symmetrically, with an increasing supply function pS(x)p_S(x) (the lowest price at which producers will sell the xx-th unit), the producer surplus is PS=∫0X(P−pS(x)) dxPS = \int_0^X (P - p_S(x))\,dx. At the market equilibrium (where p(X)=pS(X)p(X) = p_S(X)) the sum CS+PSCS + PS is the total gain from trade, the quantity economists say a free market maximises.

python · try it yourself
import sympy as sp

x = sp.symbols("x", nonnegative=True)
demand = 30 - sp.Rational(1, 100) * x - sp.Rational(2, 100000) * x**2
X = 500
P = demand.subs(x, X)
CS = sp.integrate(demand - P, (x, 0, X))
print("price at X = 500:", P)
print("consumer surplus:", CS, "≈", float(CS))
price at X = 500: 20
consumer surplus: 8750/3 ≈ 2916.6666666666665

Present value of an income stream

Money arriving later is worth less today. With continuous compounding at rate rr, an amount AA received at time tt is worth Ae−rtA e^{-rt} now. A stream paying f(t)f(t) per year from t=0t = 0 to TT contributes f(t)e−rt Δtf(t) e^{-rt}\,\Delta t per short interval, so

PV=∫0Tf(t)e−rt dtPV = \int_0^T f(t) e^{-rt}\,dt

For a constant stream f(t)=cf(t) = c this is c(1−e−rT)/rc(1 - e^{-rT})/r, and as T→∞T \to \infty it tends to c/rc/r (a perpetuity; an improper integral that converges because the discount factor decays exponentially). The discrete version of the same idea, ∑γkrk\sum \gamma^k r_k, is the discounted return of reinforcement learning, covered in Series.

Blood flow: Poiseuille's law

In a vessel of radius RR and length ll, with pressure difference PP and blood viscosity η\eta, laminar flow has velocity profile

v(r)=P4ηl⋅(R2−r2),0≤r≤Rv(r) = \frac{P}{4\eta l} \cdot (R^2 - r^2), \qquad 0 \le r \le R

(fastest at the centre, zero at the wall). To get the flux (volume per second), slice the cross-section into thin rings: a ring of radius rr and width Δr\Delta r has area ≈2πr Δr\approx 2\pi r\,\Delta r and carries v(r)⋅2πr Δrv(r) \cdot 2\pi r\,\Delta r per second. So

F=∫0Rv(r) 2πr dr=πPR48ηlF = \int_0^R v(r)\, 2\pi r\,dr = \frac{\pi P R^4}{8\eta l}

The fourth power is the medically important part: narrowing an artery by 10% cuts the flow to 0.94≈66%0.9^4 \approx 66\%, unless the heart raises the pressure.

python · try it yourself
import sympy as sp

r, R, P, eta, l = sp.symbols("r R P eta l", positive=True)
v = P / (4 * eta * l) * (R**2 - r**2)
F = sp.integrate(v * 2 * sp.pi * r, (r, 0, R))
print("flux F =", F)
ratio = F.subs(R, sp.Rational(9, 10) * R) / F
print("flow after 10% narrowing:", ratio, "=", float(ratio))
flux F = pi*P*R**4/(8*eta*l)
flow after 10% narrowing: 6561/10000 = 0.6561

Cardiac output by dye dilution

Inject AA mg of dye into a vein near the heart and measure its concentration c(t)c(t) (mg/L) in an artery. If the heart pumps FF litres per second, the dye leaving in a short interval is c(t)⋅F Δtc(t) \cdot F\,\Delta t; all the dye eventually leaves, so A=F∫0Tc(t) dtA = F \int_0^T c(t)\,dt and

F=A∫0Tc(t) dtF = \frac{A}{\int_0^T c(t)\,dt}

The measurements are samples, so the integral is numerical (Approximate Integration):

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

t = np.arange(0, 21)                    # one reading per second for 20 s
c = 3 * t * np.exp(-0.5 * t)            # mg/L, a typical rise-and-decay curve
area = simpson(c, x=t)
A = 1.0                                 # mg injected
F = A / area
print(f"∫c dt ≈ {area:.4f} mg·s/L")
print(f"cardiac output ≈ {F:.5f} L/s = {F * 60:.2f} L/min")
∫c dt ≈ 11.9821 mg·s/L
cardiac output ≈ 0.08346 L/s = 5.01 L/min

In software: the Gini coefficient

Sort a population by income. The Lorenz curve L(u)L(u) is the share of total income earned by the poorest fraction uu of people; L(0)=0L(0) = 0, L(1)=1L(1) = 1, and perfect equality is L(u)=uL(u) = u. The Gini coefficient is twice the area between the equality line and the Lorenz curve:

G=2∫01(u−L(u)) du=1−2∫01L(u) duG = 2 \int_0^1 (u - L(u))\,du = 1 - 2 \int_0^1 L(u)\,du

G=0G = 0 is perfect equality and G→1G \to 1 means one person has everything. Analytics dashboards, ML fairness audits and decision-tree libraries (the related "Gini impurity") all compute such integrals from samples, with the trapezoid rule on the empirical Lorenz curve:

python · try it yourself
import numpy as np

rng = np.random.default_rng(3)
incomes = np.sort(rng.lognormal(mean=10, sigma=0.8, size=50_000))

L = np.concatenate([[0.0], np.cumsum(incomes) / incomes.sum()])
u = np.linspace(0, 1, len(L))
G = 1 - 2 * np.trapezoid(L, u)
print(f"Gini from the Lorenz integral: {G:.4f}")

# Theory for a lognormal: G = 2Φ(σ/√2) − 1 = erf(σ/2)
from math import erf
print(f"lognormal theory erf(0.4)    : {erf(0.4):.4f}")
Gini from the Lorenz integral: 0.4264
lognormal theory erf(0.4)    : 0.4284

Compare Average Value of a Function for another "integral as a summary statistic", and the survey's Area Under and Between Curves.

Exercises

Exercise 1: Both surpluses

Demand is p(x)=30−0.03xp(x) = 30 - 0.03x and supply is pS(x)=5+0.02xp_S(x) = 5 + 0.02x. Find the equilibrium, the consumer surplus and the producer surplus.

Answer

X=500X = 500, P=15P = 15; CS=3750CS = 3750, PS=2500PS = 2500.

Solution
30−0.03x=5+0.02x⇒0.05x=25⇒X=500, P=15CS=∫0500(15−0.03x) dx=7500−3750=3750PS=∫0500(10−0.02x) dx=5000−2500=2500\begin{aligned} &30 - 0.03x = 5 + 0.02x \quad \Rightarrow \quad 0.05x = 25 \quad \Rightarrow \quad X = 500,\ P = 15 \\ CS &= \int_0^{500} (15 - 0.03x)\,dx = 7500 - 3750 = 3750 \\ PS &= \int_0^{500} (10 - 0.02x)\,dx = 5000 - 2500 = 2500 \end{aligned}

Both regions are triangles, so 12⋅base⋅height\tfrac{1}{2} \cdot \text{base} \cdot \text{height} gives the same: 12⋅500⋅15\tfrac{1}{2} \cdot 500 \cdot 15, 12⋅500⋅10\tfrac{1}{2} \cdot 500 \cdot 10.

Exercise 2: Present value

A licence pays 1000 per year continuously for 10 years. With r=5%r = 5\%, what is it worth today? And if it paid forever?

Answer

≈7869.39\approx 7869.39; forever: 20 00020\,000.

Solution
PV=∫0101000 e−0.05t dt=1000(1−e−0.5)0.05=20000(1−e−0.5)Perpetuity: 1000/0.05=20000\begin{aligned} PV &= \int_0^{10} 1000\, e^{-0.05t}\,dt = \frac{1000 (1 - e^{-0.5})}{0.05} = 20000 (1 - e^{-0.5}) \\ &\text{Perpetuity: } 1000 / 0.05 = 20000 \end{aligned}
python · try it yourself
import math

print(f"{20000 * (1 - math.exp(-0.5)):.2f}")
7869.39

Exercise 3: Compensating a narrowed artery

An artery narrows to 80% of its radius. By what factor must the pressure difference rise to keep the same flux?

Answer

1/0.84≈2.441/0.8^4 \approx 2.44

Solution

F∝PR4F \propto P R^4, so Pnew⋅(0.8R)4=P⋅R4P_{\text{new}} \cdot (0.8R)^4 = P \cdot R^4 gives Pnew/P=1/0.4096≈2.441P_{\text{new}}/P = 1/0.4096 \approx 2.441.

Exercise 4: Gini of a formula Lorenz curve

Compute the Gini coefficient for L(u)=u3L(u) = u^3, by hand and in SymPy.

Answer

G=1/2G = 1/2

Solution
G=1−2∫01u3 du=1−2⋅14=12G = 1 - 2 \int_0^1 u^3\,du = 1 - 2 \cdot \frac{1}{4} = \frac{1}{2}
python · try it yourself
import sympy as sp

u = sp.symbols("u")
print(1 - 2 * sp.integrate(u**3, (u, 0, 1)))
1/2

Test yourself

Consumer surplus is the area

  1. under the supply curve
  2. between the demand curve and the market price line, from 0 to the quantity sold
  3. under the demand curve from 0 to ∞\infty
  4. between supply and demand to the right of equilibrium

In Poiseuille's law F=πPR4/(8ηl)F = \pi P R^4/(8\eta l), why does the factor 2πr2\pi r appear in the integrand before integrating?

  1. It is the circumference of the vessel
  2. It converts velocity to pressure
  3. A thin ring at radius rr has area ≈2πr⋅Δr\approx 2\pi r \cdot \Delta r
  4. It comes from the viscosity

A dye test integrates c(t)c(t) to 8 mg⋅s/L8\ \text{mg} \cdot \text{s/L} after injecting 0.6 mg. What is the cardiac output?

  1. 0.075 L/s=4.5 L/min0.075\ \text{L/s} = 4.5\ \text{L/min}
  2. 4.8 L/s
  3. 13.3 L/s
  4. 0.6 L/min