Chapter 39 — Exercises

These are not ordinary exercises. This is the capstone: a sequence of portfolio-build tasks that walk you, one stage at a time, through assembling a complete mathematical model in the track you have chosen. Work the tasks for your track in order — each one is a step of the modeling cycle (§39.2) — and finish with the integrative capstone task that every reader completes regardless of track.

Pick one track as your primary (Biology, Economics, Physics, or Data Science). Strong portfolios also complete one or two "cross-track bridge" tasks, to demonstrate that the toolkit transfers.

Difficulty key: ⭐ warm-up / setup · ⭐⭐ core build · ⭐⭐⭐ analysis and validation · ⭐⭐⭐⭐ extension or synthesis.

Throughout, every symbol must be defined and every tool traced to its home chapter, exactly as the worked models in the chapter were. "Define your $\beta$" is not optional bookkeeping — it is the model.


Track 1 — Biology (SIR and population dynamics)

The flagship track. Build on the SIR model derived in §39.3 (anchor from Chapter 19).

B1.State your system. Choose a real or hypothetical outbreak (influenza in a dorm, a livestock disease, even a rumor spreading as "infection"). Write the three compartments $S, I, R$ in words, name the population size $N$, and state your three modeling assumptions explicitly (homogeneous mixing? closed population? permanent immunity?). Defend or flag each.

B2.Pick and justify your parameters. Choose a transmission rate $\beta$ and recovery rate $\gamma$ (per day). State the units of each. Use $1/\gamma$ to report the average infectious period in days, and confirm it is plausible for your disease.

B3. ⭐⭐ Write the equations from scratch. Reproduce the SIR system $\frac{dS}{dt} = -\beta SI/N$, $\frac{dI}{dt} = \beta SI/N - \gamma I$, $\frac{dR}{dt} = \gamma I$ for your parameters, and explain in one sentence per equation what rate each derivative (Chapter 6) measures.

B4. ⭐⭐ Compute $R_0$ by hand and interpret it. Find $R_0 = \beta/\gamma$. State in plain English what your number means, and predict whether your outbreak takes off ($R_0 > 1$) or dies out.

B5. ⭐⭐ Find the peak condition analytically. Show that $\frac{dI}{dt} > 0$ exactly while $S/N > 1/R_0$, so the epidemic peaks when the susceptible fraction falls to $1/R_0$. Report that fraction for your $R_0$.

B6. ⭐⭐ Solve it numerically. Using the solve_ivp template from §39.3.4, integrate your system from one initial infection out to a time long enough that $I$ returns near zero. Report the peak number infected, the day it occurs, and the final attack rate $R(\infty)/N$.

B7. ⭐⭐⭐ Verify conservation. Show analytically that $\frac{d}{dt}(S+I+R)=0$, then confirm in your simulation that $S+I+R$ stays equal to $N$ to within solver tolerance. Explain why a drift would signal a bug.

B8. ⭐⭐⭐ Validate with the final-size relation. Derive $s_\infty = e^{-R_0(1-s_\infty)}$ as in §39.3.5 (divide the $S$ equation by the $R$ equation — a separable ODE from Chapter 19 — then integrate, Chapter 13). Solve it with a root-finder (Newton's method, Chapter 11) and confirm the attack rate matches your simulation. State why two independent routes agreeing is real validation.

B9. ⭐⭐⭐ Sensitivity analysis. Raise $\beta$ by 10% and re-solve. Report how much the peak day and peak height move. Is your model fragile or robust to this parameter?

B10. ⭐⭐⭐⭐ Compare interventions (optimization). Model a mask mandate as a reduction in $\beta$. For a fixed "budget" of intervention (say you may cut $\beta$ by a total of 30% over the outbreak), compare cutting it early versus at the peak. Which strategy minimizes the peak $I$? This layers optimization (Chapter 31) on the ODE (Chapter 19).

B11. ⭐⭐⭐⭐ Extend the model. Add one compartment or mechanism from §39.3.6 — SIRD (track deaths), vital dynamics (births/deaths for an endemic disease), or an age-structured contact matrix $C_{ij}$. Re-derive the equations, re-solve, and report what new prediction the extension buys you.


Track 2 — Economics (constrained optimization and welfare)

Build on the Cobb–Douglas model derived in §39.4.

E1.State your firm. Choose a product and name the two inputs as labor $L$ and capital $K$. Write the Cobb–Douglas production function $Q = AL^aK^b$, defining $A$ (total-factor productivity) and the elasticities $a, b$. State your budget $B$, wage $w$, and rental rate $r$ with units.

E2.Sanity-check your elasticities. State whether $a + b < 1$, $=1$, or $>1$ (decreasing, constant, or increasing returns to scale) and what that assumption means for your firm.

E3. ⭐⭐ Set up the Lagrangian. Write $\mathcal{L}(L,K,\lambda) = AL^aK^b - \lambda(wL + rK - B)$ and the two first-order conditions (Chapter 31). Identify each partial derivative as a marginal product (the rate-of-change idea from Chapter 6 in two variables, Chapter 29).

E4. ⭐⭐ Solve by hand. Eliminate $\lambda$ to get $\frac{a}{b}\frac{K}{L} = \frac{w}{r}$, then derive $L^* = \frac{a}{a+b}\frac{B}{w}$ and $K^* = \frac{b}{a+b}\frac{B}{r}$. Plug in your numbers and report the optimal input mix.

E5. ⭐⭐ Verify numerically. Use the scipy.optimize.minimize template from §39.4.3 to maximize $Q$ subject to your budget. Confirm the machine lands on your hand-computed $(L^*, K^*)$ (Theme 4).

E6. ⭐⭐⭐ Interpret the budget shares. Show that the optimal spend on labor is the fraction $\frac{a}{a+b}$ of the budget. State why this makes the Cobb–Douglas exponents directly testable against real expenditure data.

E7. ⭐⭐⭐ Comparative statics (a derivative). Compute $\frac{\partial L^*}{\partial w} = -\frac{a}{a+b}\frac{B}{w^2}$ and interpret its sign: how does a higher wage shift the firm toward capital (automation)? This is the derivative (Chapter 6) doing economics.

E8. ⭐⭐⭐ Add welfare via integration. Specify a linear demand curve $p_d(q)$ and supply curve $p_s(q)$, find the equilibrium $(q^*, p^*)$, then compute consumer surplus $\int_0^{q^*}(p_d(q)-p^*)\,dq$ and producer surplus $\int_0^{q^*}(p^*-p_s(q))\,dq$ as areas (Chapter 18, evaluated by FTC, Chapter 14). Show your antiderivatives.

E9. ⭐⭐⭐⭐ Optimize then integrate. Combine E4 and E8 into one narrative: optimize to find the firm's input choice, integrate to find the welfare created at equilibrium. Present both results with units and a single plot.

E10. ⭐⭐⭐⭐ Stress your assumptions. Replace Cobb–Douglas with a CES production function (or change returns to scale) and report how the optimal mix changes. Flag explicitly where the smooth-substitution assumption breaks down for a real factory.


Track 3 — Physics (orbits, motion, energy)

Build on the Hohmann transfer derived in §39.5.

P1.State your maneuver. Choose two circular orbits (e.g., low-Earth orbit to geostationary) and give their radii $r_1, r_2$ from the body's center and the gravitational parameter $\mu = GM$ with units.

P2.Compute the circular speeds. Using $v_{\text{circ}} = \sqrt{\mu/r}$ (the $a=r$ case of vis-viva), find $v_1$ and $v_2$ by hand.

P3. ⭐⭐ Build the transfer ellipse. Compute the transfer semimajor axis $a_t = (r_1+r_2)/2$ and explain geometrically (Chapter 27) why the ellipse is tangent to the inner circle at perigee and the outer at apogee.

P4. ⭐⭐ Compute the two burns. Using vis-viva $v^2 = \mu(2/r - 1/a_t)$, find the perigee speed $v_p$ and apogee speed $v_a$, then $\Delta v_1 = v_p - v_1$ and $\Delta v_2 = v_2 - v_a$. Report the total $\Delta v$ budget. Reproduce the §39.5.2 numbers if you used the textbook's radii.

P5. ⭐⭐ Connect energy to integration. Explain why vis-viva is conservation of energy, and why energy is the integral of force over displacement (work, Chapter 18). Write the work integral $\int \mathbf{F}\cdot d\mathbf{r}$ and state its sign for each burn.

P6. ⭐⭐⭐ Transfer time via Kepler. Compute the transfer time as half the period of the transfer ellipse, $t = \pi\sqrt{a_t^3/\mu}$ (Kepler's third law, a conic-section fact, Chapter 27). Report it in hours.

P7. ⭐⭐⭐ Simulate the trajectory. Numerically integrate the vector ODE $\ddot{\mathbf{r}} = -\mu\,\mathbf{r}/\|\mathbf{r}\|^3$ (Chapters 19 and 28) with solve_ivp, applying your two computed $\Delta v$'s at the right moments. Confirm the satellite arrives on the outer circle.

P8. ⭐⭐⭐ Validate by conservation. Track the specific orbital energy $\frac12\|\mathbf{v}\|^2 - \mu/\|\mathbf{r}\|$ along your simulated coast arcs and confirm it is constant between burns (it should jump only at the burns). Drift signals a numerical or setup bug.

P9. ⭐⭐⭐⭐ Optimize. Argue (or test by comparison) that the two-burn Hohmann transfer is the minimum-$\Delta v$ maneuver for these radii — an optimization result (Chapter 10). Compare against a bi-elliptic transfer for a large radius ratio.

P10. ⭐⭐⭐⭐ Add realism, flag the gap. Add a small $J_2$ oblateness correction or a finite-burn duration and report how far the prediction shifts. State plainly which two-body assumptions you broke.


Track 4 — Data Science (gradient descent and curve fitting)

Build on the gradient-descent fit derived in §39.6 (anchor from Chapters 6 and 30).

D1.State your dataset. Choose or generate data $(x_i, y_i)$ and the model you will fit (start with a line $\hat y = mx + c$). Name the $n$ data points and what $x$ and $y$ mean physically.

D2.Write the loss. State the mean squared error $L(m,c) = \frac1n\sum_i(mx_i + c - y_i)^2$ and explain why it is a sum — an accumulation of error (Chapter 13).

D3. ⭐⭐ Derive the gradient by hand. Compute $\frac{\partial L}{\partial m} = \frac{2}{n}\sum_i(mx_i+c-y_i)x_i$ and $\frac{\partial L}{\partial c} = \frac{2}{n}\sum_i(mx_i+c-y_i)$ using the chain rule (Chapter 7). These are the partial derivatives of Chapter 29 / the gradient of Chapter 30.

D4. ⭐⭐ Implement gradient descent. Code the update $m \leftarrow m - \eta\,\partial L/\partial m$, $c \leftarrow c - \eta\,\partial L/\partial c$ from §39.6.2. Choose a learning rate $\eta$ and run to convergence. Report your fitted $(m, c)$.

D5. ⭐⭐ Validate against the closed form. Solve the same fit with the exact least-squares formula (np.linalg.lstsq) and confirm gradient descent converges to it. Explain why a convex loss has a single minimum the gradient must reach.

D6. ⭐⭐⭐ Tune the learning rate. Demonstrate the failure modes from the §39.6.2 pitfall: an $\eta$ so small convergence stalls, and an $\eta$ so large the loss diverges to nan. Report the rough range of $\eta$ that works and explain why feature scaling widens it.

D7. ⭐⭐⭐ Plot the descent. Plot the loss versus iteration (it should decrease monotonically for a good $\eta$) and the fitted line over the data. Show shape, not just numbers (§39.9).

D8. ⭐⭐⭐ Cross-validate. Hold out 20% of your data, fit on the rest, and report training versus held-out error. State what a large gap would mean (overfitting, §39.8).

D9. ⭐⭐⭐⭐ Fit a nonlinear model. Replace the line with a model that needs real optimization — logistic growth $\hat y = \frac{A}{1+e^{-k(x-x_0)}}$ or a quadratic — derive its gradient, and fit by gradient descent. Report the fitted parameters and one inflection point or saturation level you can read off.

D10. ⭐⭐⭐⭐ Connect to ML. Explain in a paragraph how your three-line update is the same step that trains a neural network (backpropagation = the multivariable chain rule of Chapter 30, applied layer by layer; Adam = refined gradient descent). Name what changes (non-convex loss) and what does not (parameter $\leftarrow$ parameter $- \eta\nabla L$).


Cross-Track Bridge Tasks (any reader)

X1. ⭐⭐⭐ Read the synthesis table across a row. Take the integral row of the §39.7 table and write one sentence explaining how the same tool (accumulation) appears as the SIR final-size relation, consumer surplus, orbital work, and accumulated loss. Do the same for one other row.

X2. ⭐⭐⭐⭐ Borrow a tool. Apply a tool from a track you did not choose to your own model. Example: use gradient descent (Data Science) to calibrate your SIR $\beta, \gamma$ to a synthetic outbreak curve; or use the integral (Biology's final-size logic) to compute a cumulative quantity in your physics or economics model.


Final Integrative Capstone Task (every reader)

C1. ⭐⭐⭐⭐ Assemble and communicate the portfolio. Following the nine-part structure of §39.9, write up your complete model: (1) problem statement, (2) assumptions defended, (3) the equations with every symbol defined, (4) a tools-used table in the style of §39.7 citing the home chapter of each tool, (5) reproducible code, (6) labeled results with headline numbers, (7) validation including at least one independent cross-check (as the final-size relation validated SIR), (8) limitations and where the model breaks, (9) a plain-language conclusion. Lead with the punchline, not the algebra (§39.9). This single deliverable is the capstone.


Difficulty Distribution

Tier Count Tasks
⭐ (warm-up / setup) 8 B1, B2, E1, E2, P1, P2, D1, D2
⭐⭐ (core build) 12 B3, B4, B5, B6, E3, E4, E5, P3, P4, D3, D4, P5*
⭐⭐⭐ (analysis & validation) 14 B7, B8, B9, E6, E7, E8, P6, P7, P8, D5, D6, D7, D8, X1
⭐⭐⭐⭐ (extension & synthesis) 10 B10, B11, E9, E10, P9, P10, D9, D10, X2, C1
Total 44 across four tracks + bridges + capstone

*P5 is rated ⭐⭐.

(Work only your chosen track's tasks plus the bridges and the capstone — roughly 12–14 tasks for one track. The full count reflects all four parallel tracks.)

Solutions and modeling rubrics for selected tasks appear in appendices/answers-to-selected.md.