P00.09 ยท Lesson 09 of 15

Symbolic Math with SymPy

Let the computer do the algebra; keep the physics, and the checking, for yourself.

computational Time unmeasured

Build it Derive and lambdify an equation of motion

Learning outcomes
  1. Derive the equation of motion of a point mass falling under gravity with quadratic drag, state where it is valid, and find its terminal velocity and exact solution.
  2. Encode the derivation in SymPy: symbols with assumptions, Eq, solve, diff, integrate, limit, series, simplify.
  3. Turn a symbolic expression into a fast NumPy function with lambdify and check it against hand values, limiting cases and a SciPy integration.
  4. Check a symbolic derivative against a finite difference and explain the error curve (truncation versus rounding).
Prerequisites

P00.03, P00.06, P00.07; Bridge B1 (algebra, trig); skill check: can differentiate tanhโก\tanh and integrate 1/(a2โˆ’v2)1/(a^2 - v^2) with a table; knows what an initial condition is.

Engineering question

How fast does a 1.2 kg instrument package fall after release, when does drag stop it accelerating, and how far has it fallen by then?

Full lesson specification (11 more items)
Assumptions and limits

Point mass; one-dimensional vertical motion with the object never moving upward (vโ‰ฅ0v \ge 0); constant gravity gg; constant air density and drag coefficient, so k=12ฯCDAk = \tfrac12\rho C_D A is constant; drag exactly quadratic in speed. Fails for a 10 km drop (density changes), near Mach 1 (CDC_D changes), at very low speed where drag becomes linear in vv (Stokes regime), and for a body that tumbles (AA and CDC_D change).

Analytical work

Separation of variables to the tanhโก\tanh solution; terminal velocity; distance fallen; small-time series; no-drag limit.

Computational deliverable

starter/main.py: acceleration_expr, terminal_velocity_expr, velocity_expr, position_expr, ode_residual, no_drag_limit, small_time_series, acceleration_derivative_expr, four lambdify_* functions, central_difference, derivative_check, velocity_derivative_check. Tests prove: the symbolic solution satisfies the ODE identically, xโ€ฒ=vx' = v, the kโ†’0k \to 0 limit is gtgt, the series coefficients are right, lambdified functions match hand values and limits, and the finite-difference check converges at second order.

Practical activity

computational experiment: measure the error of the finite-difference derivative against the symbolic one over eight decades of step size and locate the truncation/rounding crossover.

Equipment

None

Safety

None beyond normal computer use. The lesson does not ask you to drop anything; P00.15 does, with its own safety box.

Evidence

Completed main.py, passing tests, fall_with_drag.png, the error-versus-hh table and log-log plot, and a short note explaining the shape of that curve.

Assessment

assessments/phase-00/grading-rubric.md; competencies 1 (reasoning), 2 (analytical), 3 (computational); pass when the derivation is complete with assumptions named, all public tests pass, and the error-curve note identifies both regimes with numbers.

References

@sympy-tutorial "Introductory Tutorial": "Gotchas" (Symbols, Equals signs), "Basic Operations", "Simplification", "Calculus", "Solvers" (required-free); @numpy-userguide "NumPy quickstart" for the arrays lambdify returns (supplementary-free).

Extensions

โ˜… Solve the ODE directly with sp.dsolve and show the result is the same tanh. โ˜… Add the upward-motion branch (v<0v < 0) with sp.Piecewise or sp.sign and verify against solve_ivp. โ˜… Let ฯ\rho follow the ISA from P00.03 and show the symbolic approach stops helping.

Time

unmeasured

1. The engineering problem

An instrument package of mass 1.2 kg, frontal area 0.01 mยฒ and drag coefficient about 1.0 is released from a balloon or a slow aircraft. The parachute team needs three numbers before the flight: the speed it will reach if the parachute fails to open (terminal velocity), how long it takes to get there, and how far it falls meanwhile. Those numbers set the opening altitude and the size of the recovery area.

The physics is Newton's second law with two forces. The hard part is not the physics; it is the algebra of solving a non-linear differential equation and then trusting the result. Done by hand, that algebra is where sign errors and lost factors of two live. Done by a computer algebra system, it is fast and exact, but a computer algebra system will happily simplify a wrong equation. So the lesson has two halves: use SymPy (the Python library for symbolic mathematics) to derive and solve, and then use the tools of P00.07 to check the symbolic result against limiting cases, a finite-difference derivative and a numerical integration.

Success criterion: an exact expression for v(t)v(t) and x(t)x(t) that satisfies the equation of motion identically (not just numerically), a NumPy function made from it that agrees with scipy.integrate.solve_ivp to better than 10โˆ’710^{-7} m/s, and a plot of the three predictions.

2. Understand and derive

2.1 Forces and the equation of motion

Take downward as positive and let vv be the speed (so vโ‰ฅ0v \ge 0 while falling). Two forces act: weight mgmg downward, and aerodynamic drag D=12ฯCDAv2D = \tfrac12\rho C_D A v^2 opposing the motion, i.e. upward.

Free-body diagram of a falling package of mass m, frontal area A and drag coefficient C_D: drag D = k vยฒ acts upward, opposing the motion, and weight m g acts downward; the speed v is positive downward, the direction taken as positive.
Figure 1. Forces on the falling package, with downward taken as positive. Drag points up and grows as vยฒ, so it eventually balances the constant weight.

Define the drag constant

k=12ฯCDA[kg/m],k = \tfrac12 \rho C_D A \qquad [\mathrm{kg/m}],

so D=kv2D = kv^2. Units: kgโ€‰mโˆ’3โ‹…m2=kgโ€‰mโˆ’1\mathrm{kg\,m^{-3}\cdot m^2 = kg\,m^{-1}}, and kv2kv^2 has units kgโ€‰mโˆ’1โ€‰m2โ€‰sโˆ’2=N\mathrm{kg\,m^{-1}\,m^2\,s^{-2} = N}. Newton's second law:

mdvdt=mgโˆ’kv2โŸนdvdt=gโˆ’kmv2.m\frac{\mathrm{d}v}{\mathrm{d}t} = mg - kv^2 \quad\Longrightarrow\quad \frac{\mathrm{d}v}{\mathrm{d}t} = g - \frac{k}{m}v^2.

Assumptions used so far: point mass (no rotation), constant gg (altitude change small compared with Earth's radius), constant ฯ\rho, CDC_D and AA (no tumbling, low Mach, altitude change small compared with the atmosphere's scale height of about 8 km), and vโ‰ฅ0v \ge 0 (if the body could move upward the drag would have to be written โˆ’kโ€‰vโˆฃvโˆฃ-k\,v|v|). For the example: k=0.5ร—1.225ร—1.0ร—0.01=0.006125k = 0.5 \times 1.225 \times 1.0 \times 0.01 = 0.006125 kg/m.

2.2 Terminal velocity

Acceleration vanishes when drag balances weight:

gโˆ’kmvt2=0โ€…โ€Šโ‡’โ€…โ€Švt=mgk.g - \frac{k}{m}v_t^2 = 0 \;\Rightarrow\; v_t = \sqrt{\frac{mg}{k}}.

Units: kgโ‹…mโ€‰sโˆ’2/(kgโ€‰mโˆ’1)=m/s\sqrt{\mathrm{kg \cdot m\,s^{-2} / (kg\,m^{-1})}} = \mathrm{m/s}. For the example, vt=1.2ร—9.80665/0.006125=43.8v_t = \sqrt{1.2 \times 9.80665/0.006125} = 43.8 m/s (158 km/h). Note the scaling: doubling the mass raises vtv_t by 2\sqrt2; doubling the area lowers it by 2\sqrt2. A 1 kg payload under a 2 mยฒ parachute (CDโ‰ˆ1.5C_D \approx 1.5) has vtโ‰ˆ2.3v_t \approx 2.3 m/s. This is the first limiting case a test should check: a(vt)=0a(v_t) = 0 exactly.

2.3 Exact solution by separation of variables

Write the equation as dvdt=gvt2โ€‰(vt2โˆ’v2)\dfrac{\mathrm{d}v}{\mathrm{d}t} = \dfrac{g}{v_t^2}\,(v_t^2 - v^2), using k/m=g/vt2k/m = g/v_t^2. Separate:

โˆซ0vdvโ€ฒvt2โˆ’vโ€ฒ2=gvt2โ€‰t.\int_0^{v} \frac{\mathrm{d}v'}{v_t^2 - v'^2} = \frac{g}{v_t^2}\,t.

The left side is a standard integral: 1vtartanhโก(v/vt)\dfrac{1}{v_t}\operatorname{artanh}(v/v_t) for 0โ‰คv<vt0 \le v < v_t. Hence

v(t)=vttanhโกโ€‰โฃ(gโ€‰tvt),v(0)=0.v(t) = v_t \tanh\!\left(\frac{g\,t}{v_t}\right), \qquad v(0) = 0.

Check it: dv/dt=gโ€‰(1โˆ’tanhโก2)=gโˆ’(g/vt2)โ€‰v2=gโˆ’(k/m)v2\mathrm{d}v/\mathrm{d}t = g\,(1 - \tanh^2) = g - (g/v_t^2)\,v^2 = g - (k/m)v^2. โœ“ The time constant is ฯ„=vt/g\tau = v_t/g (4.5 s for the example): after t=2.65ฯ„t = 2.65\tau the speed is 99 % of terminal.

Integrate once more for the distance fallen with x(0)=0x(0) = 0:

x(t)=โˆซ0tvttanhโกgtโ€ฒvtโ€‰dtโ€ฒ=vt2gโ€‰lnโกcoshโกgโ€‰tvt.x(t) = \int_0^t v_t \tanh\frac{g t'}{v_t}\,\mathrm{d}t' = \frac{v_t^2}{g}\,\ln\cosh\frac{g\,t}{v_t}.

Check: dx/dt=(vt2/g)โ‹…(g/vt)tanhโก(โ‹…)=vttanhโก(โ‹…)=v\mathrm{d}x/\mathrm{d}t = (v_t^2/g)\cdot(g/v_t)\tanh(\cdot) = v_t\tanh(\cdot) = v. โœ“

2.4 Two more limiting cases and a series

  • No drag: as kโ†’0k \to 0, vtโ†’โˆžv_t \to \infty and tanhโก(gt/vt)โ‰ˆgt/vt\tanh(gt/v_t) \approx gt/v_t, so vโ†’gtv \to gt: free fall. A test asserts limit(v, k, 0) == g*t.
  • Long time: tanhโกโ†’1\tanh \to 1, so vโ†’vtv \to v_t and xโ‰ˆvttโˆ’(vt2/g)lnโก2x \approx v_t t - (v_t^2/g)\ln 2: the body falls as if at terminal speed, minus a fixed distance lost while accelerating.
  • Small time: tanhโกu=uโˆ’u3/3+2u5/15โˆ’โ€ฆ\tanh u = u - u^3/3 + 2u^5/15 - \dots with u=gt/vtu = gt/v_t gives
v(t)=gtโˆ’g2k3mโ€‰t3+2g3k215m2โ€‰t5โˆ’โ€ฆv(t) = gt - \frac{g^2 k}{3m}\,t^3 + \frac{2g^3k^2}{15m^2}\,t^5 - \dots

The t3t^3 term is drag's first bite. Its relative size is gkt2/(3m)gkt^2/(3m), so drag changes the speed by 1 % after t=0.03โ€‰m/(gk)=0.77t = \sqrt{0.03\,m/(gk)} = 0.77 s for the example. Series like this are how you decide when a simpler model (free fall) is good enough.

2.5 Checking a derivative numerically

If ff is smooth, the central difference

fโ€ฒ(x)โ‰ˆf(x+h)โˆ’f(xโˆ’h)2hf'(x) \approx \frac{f(x+h) - f(x-h)}{2h}

has truncation error h26fโ€ฒโ€ฒโ€ฒ(ฮพ)\tfrac{h^2}{6}f'''(\xi), and rounding error about ฮตโˆฃf(x)โˆฃ/h\varepsilon |f(x)|/h with ฮตโ‰ˆ2.2ร—10โˆ’16\varepsilon \approx 2.2 \times 10^{-16}. The total is smallest where the two balance, hoptโ‰ˆ(3ฮตโˆฃfโˆฃ/โˆฃfโ€ฒโ€ฒโ€ฒโˆฃ)1/3h_{\text{opt}} \approx (3\varepsilon |f|/|f'''|)^{1/3}, which is around 10โˆ’510^{-5} to 10โˆ’410^{-4} for quantities of order one. For a(v)=gโˆ’kv2/ma(v) = g - kv^2/m, a quadratic, fโ€ฒโ€ฒโ€ฒ=0f''' = 0: the central difference is exact up to rounding, so the check in derivative_check measures pure rounding (about 10โˆ’1310^{-13}). For v(t)v(t), which has non-zero vโ€ฒโ€ฒโ€ฒv''', the error in velocity_derivative_check falls as h2h^2 until rounding takes over. Seeing both behaviours is the point of part 4.

2.6 How SymPy thinks

Three facts from the @sympy-tutorial "Gotchas" page that save hours. First, a SymPy symbol is not a Python variable: t = sp.symbols("t") makes a mathematical object named tt; assigning to the Python name later does not change expressions already built. Second, == tests structural equality, not mathematical equality: (x+1)**2 == x**2 + 2*x + 1 is False; use sp.simplify(a - b) == 0 or sp.expand. Third, assumptions matter: declaring positive=True lets SymPy simplify gm/k2\sqrt{gm/k}^2 to gm/kgm/k and pick the positive root of vt2=gm/kv_t^2 = gm/k without a case split. Finally, lambdify((t, m, g, k), expr, modules="numpy") compiles an expression to a plain Python function that accepts NumPy arrays: that is the bridge from derivation to computation.

Every step of the hand derivation in 2.1โ€“2.5 has a one-line SymPy counterpart, and the code in part 3 is nothing more than this table written out:

Derivation step SymPy call What to check
declare the quantities sp.symbols("t v m g k", positive=True) assumptions match the physics (m,k,g>0m, k, g > 0)
write Newton's law g - k*v**2/m units by hand (SymPy does not track them)
find vtv_t from a=0a = 0 sp.solve(sp.Eq(a, 0), v) exactly one positive root
verify a candidate v(t)v(t) sp.simplify(sp.diff(vc, t) - a.subs(v, vc)) returns 0, and a wrong candidate does not
distance fallen sp.integrate(v_expr, t) fix the constant so x(0)=0x(0) = 0; differentiate back
no-drag limit sp.limit(v_expr, k, 0) equals g*t
small-time behaviour sp.series(v_expr, t, 0, 4).removeO() leading term g*t, no t2t^2 term
sensitivity โˆ‚a/โˆ‚v\partial a/\partial v sp.diff(a, v) matches a central difference
make it fast sp.lambdify((t, m, g, k), v_expr, "numpy") hand values, limits, solve_ivp

3. Build the computational model

Open starter/main.py. The symbols are declared once at the top so every function shares them.

Step 1: the equation of motion and terminal velocity

import sympy as sp
t, v, m, g, k = sp.symbols("t v m g k", positive=True)

def acceleration_expr():
    return g - k * v**2 / m

def terminal_velocity_expr():
    roots = sp.solve(sp.Eq(acceleration_expr(), 0), v)
    (root,) = [r for r in roots if r.is_positive]      # exactly one, thanks to positive=True
    return root

Step 2: the exact solution, and the identity check

def velocity_expr():
    vt = terminal_velocity_expr()
    return vt * sp.tanh(g * t / vt)

def ode_residual(v_candidate):
    return sp.simplify(sp.diff(v_candidate, t) - acceleration_expr().subs(v, v_candidate))

ode_residual(velocity_expr()) must return exactly 0. Try ode_residual(g*t) too: it returns โˆ’g2kt2/m-g^2kt^2/m, which is drag's missing term, and the test test_ode_residual_is_nonzero_for_a_wrong_candidate makes sure your residual function is not accidentally always zero. position_expr is vt2/gโ‹…logโกcoshโก(gt/vt)v_t^2/g \cdot \log\cosh(gt/v_t); the test differentiates it and compares with velocity_expr.

Step 3: limits and series

no_drag_limit is sp.limit(velocity_expr(), k, 0). small_time_series(order) is sp.series(velocity_expr(), t, 0, order).removeO(); the test reads off the tt, t2t^2 and t3t^3 coefficients with sp.Poly. acceleration_derivative_expr is sp.diff(acceleration_expr(), v).

Step 4: lambdify

def lambdify_velocity():
    return sp.lambdify((t, m, g, k), velocity_expr(), modules="numpy")

Same pattern for acceleration, position and da/dv\mathrm{d}a/\mathrm{d}v. Argument order is a contract: the tests call vel(ts, M, G, K).

Step 5: finite differences

central_difference(f, x, h) is three lines and must reject hโ‰ค0h \le 0. derivative_check compares the lambdified da/dv\mathrm{d}a/\mathrm{d}v with the central difference of the lambdified aa at speed v0v_0. velocity_derivative_check compares a(v(t0))a(v(t_0)) with the central difference of v(t)v(t) at t0t_0: this is the ODE verified numerically, which is what you would do if no closed form existed.

Verify

  • Analytic case: test_velocity_solves_the_ode_with_zero_initial_speed (residual exactly 0), test_position_is_the_integral_of_velocity.
  • Limiting cases: v(0)=0v(0) = 0; a(vt)=0a(v_t) = 0; kโ†’0k \to 0 gives gtgt; tโ†’โˆžt \to \infty gives vtv_t; scaling of vtv_t with mm and kk.
  • Conservation-like property: the trapezoid integral of the lambdified vv reproduces the lambdified xx to 10โˆ’410^{-4} m over 10 s; vv is monotone and bounded by vtv_t.
  • Convergence: test_velocity_derivative_check_converges_at_second_order requires a logโก2\log_2 rate above 1.8 as hh halves.

Compare

main() integrates the same ODE with scipy.integrate.solve_ivp (rtol=1e-10, atol=1e-12) and reports the maximum difference from the exact solution over 15 s: about 9ร—10โˆ’99 \times 10^{-9} m/s. The difference is the integrator's error, not the formula's: tighten the tolerances and it shrinks; loosen them to the defaults (rtol=1e-3) and it grows to 10โˆ’210^{-2} m/s. The exact solution is the reference here; in Phase 03 the roles reverse and the integrator is tested on problems like this one precisely because the answer is known.

4. Experiment at home, or investigate real data

Mode: computational experiment. Map the error of the finite-difference derivative against the symbolic one.

  1. Fix the example parameters (m=1.2m = 1.2 kg, g=9.80665g = 9.80665 m/sยฒ, k=0.006125k = 0.006125 kg/m) and t0=3t_0 = 3 s.
  2. For hโˆˆ{10โˆ’1,10โˆ’2,โ€ฆ,10โˆ’8}h \in \{10^{-1}, 10^{-2}, \dots, 10^{-8}\} record velocity_derivative_check(3.0, m, g, k, h) and derivative_check(20.0, m, g, k, h).
  3. Before running, write down your prediction: at which hh is the first check smallest, and what slope do you expect on a log-log plot on each side of that minimum?
  4. Plot both errors against hh on log-log axes, add the lines Ch2C h^2 and ฮตโˆฃvโˆฃ/h\varepsilon |v|/h, and save as fd_error_vs_h.png.

Raw data format: CSV with columns h, err_velocity_ode, err_dadv.

5. Validate and improve

Put the three error estimates side by side: the analytic truncation term h26โˆฃvโ€ฒโ€ฒโ€ฒ(t0)โˆฃ\tfrac{h^2}{6}|v'''(t_0)|, the rounding estimate ฮตโˆฃv(t0)โˆฃ/h\varepsilon|v(t_0)|/h, and the measurement. You should see the velocity check fall by a factor of 100 per decade from h=10โˆ’1h = 10^{-1} (3.1ร—10โˆ’53.1 \times 10^{-5} m/sยฒ) to 10โˆ’310^{-3} (3.2ร—10โˆ’93.2 \times 10^{-9}), reach a minimum near h=10โˆ’4h = 10^{-4} (5ร—10โˆ’115 \times 10^{-11}), and then rise by a factor of 10 per decade: 2.8ร—10โˆ’92.8 \times 10^{-9} at 10โˆ’610^{-6} and 4ร—10โˆ’74 \times 10^{-7} at 10โˆ’810^{-8}. The slope +2 on the left is truncation; the slope โˆ’1 on the right is rounding, because the subtraction v(t+h)โˆ’v(tโˆ’h)v(t+h) - v(t-h) loses leading digits as hh shrinks. The optimum sits near (3ฮตโˆฃvโˆฃ/โˆฃvโ€ฒโ€ฒโ€ฒโˆฃ)1/3โ‰ˆ1.3ร—10โˆ’4(3\varepsilon|v|/|v'''|)^{1/3} \approx 1.3 \times 10^{-4} with โˆฃvโˆฃโ‰ˆ25|v| \approx 25 m/s and โˆฃvโ€ฒโ€ฒโ€ฒโˆฃโ‰ˆ0.02|v'''| \approx 0.02 m/sโด for this case, not at the textbook ฮต1/3โ‰ˆ6ร—10โˆ’6\varepsilon^{1/3} \approx 6 \times 10^{-6}, which assumes โˆฃvโˆฃโˆผโˆฃvโ€ฒโ€ฒโ€ฒโˆฃโˆผ1|v| \sim |v'''| \sim 1. Explain that discrepancy in your note: the rule of thumb has hidden scale factors.

The acceleration check behaves differently: flat at 10โˆ’1510^{-15} to 10โˆ’1310^{-13} for every hh above 10โˆ’410^{-4}, because a quadratic has no h2h^2 truncation term; only rounding is visible, and it too grows as hh shrinks. If you had seen a smooth h2h^2 decay there you would have to suspect your acceleration_expr is not quadratic.

Improvement: for the velocity check, use the five-point stencil (โˆ’f(x+2h)+8f(x+h)โˆ’8f(xโˆ’h)+f(xโˆ’2h))/(12h)(-f(x+2h) + 8f(x+h) - 8f(x-h) + f(x-2h))/(12h) and show the left slope becomes +4 while the right slope stays โˆ’1, moving the optimum to a larger hh and a smaller minimum error.

6. Defend your work

Submit main.py, the test log, fall_with_drag.png, fd_error_vs_h.png with its CSV, and a one-page note (template in projects/_template/report-template.md) containing the derivation with assumptions, the three predictions for the package (vtv_t, time to 99 % of vtv_t, distance fallen by then) and the error-curve explanation.

Adversarial self-checks

  • What if the mass doubles? vtv_t rises by 2\sqrt2 and the time constant vt/gv_t/g with it; the distance fallen in the first second barely changes. Check all three with the lambdified functions.
  • What if vโ†’0v \to 0? Drag vanishes quadratically, so the early motion is pure free fall; is there a speed below which quadratic drag is the wrong model (hint: Reynolds number below about 1)?
  • Which assumption fails first in the real world? For a 1 km drop, none seriously; for a 30 km stratospheric drop, constant density: ฯ\rho at 30 km is 1.5 % of sea level, so the early "terminal velocity" is eight times larger and the body decelerates as it descends. The symbolic solution no longer exists in closed form.
  • What measurement could falsify the model? A video of the drop (P00.15) giving v(t)v(t): a fit of vttanhโก(gt/vt)v_t\tanh(gt/v_t) with vtv_t free should recover kk within the uncertainty of ฯCDA\rho C_D A.
  • Does the result survive a change of tool? solve_ivp agrees to 10โˆ’810^{-8} m/s; sp.dsolve returns the same tanhโก\tanh (extension). Which decision changes if CDC_D is uncertain by ยฑ20 %? vtv_t by โˆ“10 %: the parachute opening altitude must carry that margin.

Check yourself

  1. Write the equation of motion for a falling body with quadratic drag and name the two assumptions that make kk a constant.
  2. Derive the units of kk and of vt=mg/kv_t = \sqrt{mg/k}.
  3. Why is sp.simplify(a - b) == 0 the right test of equality and a == b the wrong one?
  4. State the no-drag limit of v(t)v(t) and the long-time limit, and say which SymPy function finds each.
  5. The central difference of a quadratic is exact. Why, then, does derivative_check not return exactly zero?
  6. For the example package, how long until the speed is within 1 % of terminal, and how far has it fallen by then? (Use artanhโก(0.99)=2.647\operatorname{artanh}(0.99) = 2.647.)
  7. What does positive=True buy you when solving vt2=gm/kv_t^2 = gm/k?
  8. On a log-log plot of finite-difference error against hh, what slopes do you expect on each side of the minimum, and which physical constant sets the right-hand side?

Problem set

Attempt every problem before opening solutions/. Record what you tried. State units on every numerical answer and say which results are exact (symbolic) and which are numerical.

Several problems use your personal seed s: the day of the month you were born (1โ€“31).

1. (Warm-up: the package)

An instrument package has mass m=0.5+0.1sm = 0.5 + 0.1s kg, drag coefficient CD=1.0C_D = 1.0 and frontal area A=0.010A = 0.010 mยฒ. Sea-level air, ฯ=1.225\rho = 1.225 kg/mยณ, g=9.80665g = 9.80665 m/sยฒ.

Find: (a) the drag constant kk in kg/m; (b) the terminal velocity vtv_t; (c) the time constant ฯ„=vt/g\tau = v_t/g; (d) the time to reach 99 % of vtv_t (use artanhโก(0.99)=2.6467\operatorname{artanh}(0.99) = 2.6467); (e) the distance fallen by then. Check (b) with terminal_velocity_expr().subs(...) and (e) with lambdify_position(). Answer form: five numbers with units, four significant figures.

2. (Derivation: solve the equation of motion by hand)

Starting from mโ€‰dv/dt=mgโˆ’kv2m\,\mathrm{d}v/\mathrm{d}t = mg - kv^2 with v(0)=0v(0) = 0:

(a) Separate variables and integrate to obtain v(t)=vttanhโก(gt/vt)v(t) = v_t\tanh(gt/v_t). Name each assumption where you use it (in particular where you need v<vtv < v_t). (b) Integrate again to obtain x(t)=(vt2/g)lnโกcoshโก(gt/vt)x(t) = (v_t^2/g)\ln\cosh(gt/v_t) with x(0)=0x(0) = 0. (c) Show that for tโ‰ซvt/gt \gg v_t/g, x(t)โ‰ˆvttโˆ’(vt2/g)lnโก2x(t) \approx v_t t - (v_t^2/g)\ln 2, and interpret the constant. (d) Reproduce (a) in SymPy with sp.dsolve (extension) or by checking ode_residual, and (b) with sp.integrate. Report whether SymPy's form is identical to yours and, if not, how you proved them equal.

Answer form: derivation with steps named; one short paragraph for (c); SymPy transcript for (d).

3. (Unfamiliar scenario: thrown upward)

The same package (use m=1.2m = 1.2 kg, k=0.006125k = 0.006125 kg/m) is launched vertically upward at v0=30v_0 = 30 m/s. Take upward positive; drag now acts downward, and so does gravity.

(a) Write the equation of motion for the upward leg and explain why it is not the same equation as in the lesson with a sign change of vv. (b) Solve it (by hand or with SymPy) to get v(t)=vttanโกโ€‰โฃ(arctanโก(v0/vt)โˆ’gt/vt)v(t) = v_t\tan\!\big(\arctan(v_0/v_t) - gt/v_t\big) and verify the result with an ode_residual-style check. (c) Find the time to the apex and the apex height, both symbolically and numerically, and compare with the no-drag values v0/gv_0/g and v02/(2g)v_0^2/(2g). (d) Why does the lesson's velocity_expr not describe the fall after the apex if you simply shift the time origin? (It does; say why, in one sentence.)

Answer form: equation, derivation or SymPy transcript, four numbers with units, two sentences.

4. (Numerical, uses your code: the error curve)

Run the computational experiment of lesson part 4: velocity_derivative_check(3.0, 1.2, 9.80665, 0.006125, h) and derivative_check(20.0, ...) for h=10โˆ’1,โ€ฆ,10โˆ’8h = 10^{-1}, \dots, 10^{-8}.

(a) Tabulate and plot on log-log axes. Fit the slope on each side of the minimum for the velocity check. (b) Compute the predicted optimum hopt=(3ฮตโˆฃvโˆฃ/โˆฃvโ€ฒโ€ฒโ€ฒโˆฃ)1/3h_{\text{opt}} = (3\varepsilon|v|/|v'''|)^{1/3} at t0=3t_0 = 3 s using SymPy for vโ€ฒโ€ฒโ€ฒv''', and compare with the measured minimum. (c) Implement the five-point stencil (โˆ’f(x+2h)+8f(x+h)โˆ’8f(xโˆ’h)+f(xโˆ’2h))/(12h)(-f(x+2h) + 8f(x+h) - 8f(x-h) + f(x-2h))/(12h) and repeat (a) for it. Report the new left-hand slope and the new minimum error.

Answer form: a table, two plots, two slopes with uncertainties, one paragraph.

5. (Series: when does drag matter?)

(a) From small_time_series(6) write down the relative deviation of v(t)v(t) from free fall, 1โˆ’v/(gt)1 - v/(gt), to leading order in tt. (b) Solve for the time t1t_1 at which that deviation reaches 1 % for the lesson's package, then evaluate the exact deviation at t1t_1 with lambdify_velocity and report the difference. (c) A P00.15 experiment drops a ball from 2 m and times it to 0.01 s. Using t1t_1 as the yardstick, decide whether free fall is an adequate model for that experiment with a tennis ball (m=58m = 58 g, A=3.4ร—10โˆ’3A = 3.4 \times 10^{-3} mยฒ, CDโ‰ˆ0.5C_D \approx 0.5) and with a table-tennis ball (m=2.7m = 2.7 g, A=1.26ร—10โˆ’3A = 1.26 \times 10^{-3} mยฒ, CDโ‰ˆ0.5C_D \approx 0.5).

Answer form: one formula; one time and one percentage; two yes/no decisions each with a number.

6. (Judgment: where the model stops)

For each of the following, say which assumption of the lesson's model fails, estimate the size of the effect with one number, and say whether a symbolic closed form still exists:

(a) A 30 km stratospheric balloon drop (ISA density at 30 km is about 0.018 kg/mยณ). (b) The package tumbles, with CDAC_D A varying between 0.006 and 0.014 mยฒ. (c) A 20 ยตm fog droplet falling in air (hint: compute the Reynolds number ฯvL/ฮผ\rho v L/\mu with ฮผ=1.8ร—10โˆ’5\mu = 1.8 \times 10^{-5} Paยทs using the quadratic model's own vtv_t; at Re<1Re < 1 drag is linear in vv and Stokes' law gives vt=2r2ฯwg/(9ฮผ)v_t = 2r^2\rho_w g/(9\mu)). Compare with a 2 mm raindrop. (d) The fall lasts long enough that gg changes by 0.1 % (how far is that?).

Answer form: four short paragraphs, each with a number.

7. (Hard, uses your code: linear versus quadratic drag)

A competing model uses linear drag, mโ€‰dv/dt=mgโˆ’cvm\,\mathrm{d}v/\mathrm{d}t = mg - cv.

(a) Solve it symbolically for v(0)=0v(0) = 0 and find its terminal velocity and time constant. (b) Choose cc so that both models have the same vtv_t as the lesson's package. Derive, for each model, the time to reach 90 % of vtv_t in units of vt/gv_t/g. Which model reaches terminal speed sooner, and why physically? (c) Lambdify both v(t)v(t) and plot them together with free fall for 0โ‰คtโ‰ค200 \le t \le 20 s. At t=2t = 2 s, which is faster and by how much? (d) Propose one measurement from a P00.15-style drop test that would tell the two models apart, and estimate the precision it needs.

Answer form: two formulas, two dimensionless times, a plot, one number with units, one paragraph.

Get the code

Clone the repository once, write your code in starter/main.py, then run the tests from the repository root.

pytest curriculum/phase-00/lesson-09-symbolic-math-sympy

To run the same tests against the reference solution instead:

AEFS_IMPL=solution pytest curriculum/phase-00/lesson-09-symbolic-math-sympy

Found a mistake? Every page is built from the Markdown in the repository; edit it on GitHub.