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 gives the price at which buyers will take units; it decreases. Split into small batches: the buyers of the batch near would have paid , but at the market price they pay only . Their saving is , and the total saving is the consumer surplus
Symmetrically, with an increasing supply function (the lowest price at which producers will sell the -th unit), the producer surplus is . At the market equilibrium (where ) the sum is the total gain from trade, the quantity economists say a free market maximises.
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 , an amount received at time is worth now. A stream paying per year from to contributes per short interval, so
For a constant stream this is , and as it tends to (a perpetuity; an improper integral that converges because the discount factor decays exponentially). The discrete version of the same idea, , is the discounted return of reinforcement learning, covered in Series.
Blood flow: Poiseuille's law
In a vessel of radius and length , with pressure difference and blood viscosity , laminar flow has velocity profile
(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 and width has area and carries per second. So
The fourth power is the medically important part: narrowing an artery by 10% cuts the flow to , unless the heart raises the pressure.
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 mg of dye into a vein near the heart and measure its concentration (mg/L) in an artery. If the heart pumps litres per second, the dye leaving in a short interval is ; all the dye eventually leaves, so and
The measurements are samples, so the integral is numerical (Approximate Integration):
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 is the share of total income earned by the poorest fraction of people; , , and perfect equality is . The Gini coefficient is twice the area between the equality line and the Lorenz curve:
is perfect equality and 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:
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 and supply is . Find the equilibrium, the consumer surplus and the producer surplus.
Answer
, ; , .
Solution
Both regions are triangles, so gives the same: , .
Exercise 2: Present value
A licence pays 1000 per year continuously for 10 years. With , what is it worth today? And if it paid forever?
Answer
; forever: .
Solution
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
Solution
, so gives .
Exercise 4: Gini of a formula Lorenz curve
Compute the Gini coefficient for , by hand and in SymPy.
Answer
Solution
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
- under the supply curve
- between the demand curve and the market price line, from 0 to the quantity sold
- under the demand curve from 0 to
- between supply and demand to the right of equilibrium
In Poiseuille's law , why does the factor appear in the integrand before integrating?
- It is the circumference of the vessel
- It converts velocity to pressure
- A thin ring at radius has area
- It comes from the viscosity
A dye test integrates to after injecting 0.6 mg. What is the cardiac output?
- 4.8 L/s
- 13.3 L/s
- 0.6 L/min