Watch one breath from the diaphragm to the blood: lung mechanics, airway resistance, oxygen transfer in the capillary and carbon dioxide control.
Educational model with textbook-typical numbers. Not medical advice, not a diagnostic tool, and not a model of any real patient or lung disease.
The science
Mechanics. One compartment, linear: Pmus(t) = V/C + R·Q, Q = dV/dt, V measured above FRC (2.4 L). Baseline C = 0.10 L/cmH₂O and R = 2 cmH₂O·s/L give a time constant τ = R·C = 0.2 s. Inspiration is a half-sine of muscle pressure (40 % of the cycle), expiration is passive. The ODE is integrated with RK4 (dt = 5 ms); the pressure amplitude that gives the requested tidal volume is found by bisection. For a step pressure the exact answer is V(t) = C·P·(1 − e^(−t/τ)), which is one of the checks.
Airway tree. Generation g has radius r = 9 mm·0.79g, length 0.12 m·0.8g and 2g parallel branches; the Poiseuille resistance of one generation is 8 μ L / (π r⁴ 2g). Only the shape of the distribution is used (the magnitude is calibrated to R = 2 cmH₂O·s/L, because real resistance also contains turbulent and upper-airway parts). Narrowing the airways scales the radii of generations 3 and up, so resistance grows roughly with 1/r⁴.
Ventilation and CO₂. V̇E = VT f, V̇A = (VT − VD) f with VD = 0.15 L. Alveolar ventilation follows PaCO2 = 0.863 V̇CO2/V̇A (V̇CO2 in mL/min). Oxygen use V̇O2 = 0.25 + 0.0116 W L/min (W watts of exercise), respiratory quotient 0.8, cardiac output 5 + 0.06 W L/min (assumptions).
Oxygen. Humidified inspired gas and the alveolar gas equation: PAO2 = FIO2(PB − 47) − PaCO2/R (about 100 mmHg at sea level), barometric pressure PB = 760 e^(−h/7400 m). Saturation is a Hill curve S = P^n/(P^n + P50^n), n = 2.7, P50 = 26.8 mmHg; content C = 1.34 Hb S + 0.003 P (per 100 mL). Along the capillary, Vc β(P) dP/dt = DL (PA − P) with Vc = 70 mL, β = dC/dP and DL = 21 mL/min/mmHg (rising with exercise); transit time is Vc/CO, so fast flow at exercise plus a poor membrane leaves oxygen transfer incomplete. Mixed venous oxygen follows from Fick, Cv = Ca − V̇O2/CO, solved by fixed-point iteration with a 2 % shunt.
Simplifications. One average alveolus (no V/Q mismatch, no gravity gradient, no airway collapse), linear compliance, no chemoreceptor dynamics (hypoxic drive is a simple gain), no heart-lung interaction, no acid-base chemistry. Sources by type: West, Respiratory Physiology; Guyton and Hall; OpenStax Anatomy and Physiology. This is not a diagnostic or treatment tool. Models built with Blender, scene by Three.js.