P01.08 · Lesson 08 of 18

Multivariable Functions & Partial Derivatives

Hold everything else still, nudge one thing, and watch. Then add the nudges.

computational Time unmeasured

Build it Sensitivity of lift to α and V

Learning outcomes
  1. Derive the partial derivatives of the lift of a finite wing with respect to angle of attack and airspeed, the total differential, the implicit derivative along a level curve and the chain-rule time derivative along a manoeuvre, and bound the error of the tangent-plane approximation.
  2. Implement and test a lift-sensitivity module whose partials are computed three ways (analytic, central differences, SymPy) and agree.
  3. Measure, by computational experiment, how the finite-difference error depends on the step and why one of the two partials shows no truncation error at all.
  4. Decide, for a given gust, whether the linear sensitivity estimate is good enough or the full function must be evaluated.
Prerequisites

P01.01–P01.02 (derivatives, linear approximation), P01.05 (Taylor remainder), P00.09 (SymPy diff, lambdify), P00.03 (broadcasting). Skill check: you can differentiate x2y3x^2 y^3 with respect to xx treating yy as a constant, and you know that a central difference has error ∝h2\propto h^2.

Engineering question

By how much does the lift of a light-aircraft wing change when a gust adds 5° of angle of attack or 10 m/s of airspeed, and can a first-order sensitivity estimate be trusted for that, or must the full lift function be evaluated?

Full lesson specification (11 more items)
Assumptions and limits

Incompressible flow (Mach below about 0.3); fixed wing geometry; lift coefficient depends on angle of attack only, through a lift-curve slope aa and a cubic roll-off toward stall; density fixed unless stated; quasi-steady (no unsteady aerodynamics). The cubic CL(α)C_L(\alpha) is a crude stand-in for stall: it has the right qualitative shape (a maximum, then a drop) but no claim to accuracy beyond about 12° for this wing. The model fails past stall, above Mach 0.3, and for a gust that arrives faster than the flow can adjust (a few chord-lengths of travel).

Analytical work

Partials of L=12ρV2S CL(α)L = \tfrac12\rho V^2 S\,C_L(\alpha); mixed partials and Clairaut's theorem; total differential and tangent plane with its second-order remainder; implicit differentiation of the level curve L=WL = W; the chain rule for L(α(t),V(t))L(\alpha(t), V(t)); relative (logarithmic) sensitivities; a hand calculation at 4° and 55 m/s.

Computational deliverable

starter/main.py: lift_coefficient, lift, lift_partials, partial_derivative, mixed_partial, lift_partials_sympy, lift_linearized, relative_sensitivities, level_curve_speed, level_curve_slope, lift_rate, stall_angle, tangent_plane_error_study. Tests prove: L∝V2L \propto V^2 and broadcasting; the linear model as the k3=0k_3 = 0 limit with sensitivities exactly 1 and 2; analytic partials equal central differences at second order and SymPy to 10−1210^{-12}; mixed partials agree (Clairaut); the tangent-plane error falls by 4 when the box halves and is exactly 12ρSCL ΔV2\tfrac12\rho S C_L\,\Delta V^2 along VV; the level curve carries constant lift and its implicit slope matches a finite difference; the chain-rule rate matches a finite difference along a manoeuvre and vanishes along the level curve.

Practical activity

computational experiment: step-size study of the finite-difference partials (hh from 10−110^{-1} to 10−810^{-8}) and a map of the tangent-plane error over gusts of ±6°\pm 6° and ±15\pm 15 m/s.

Equipment

None. A computer with the environment from P00.01.

Safety

None beyond normal computer use.

Evidence

Completed main.py, passing tests, lift_sensitivity.png, the hand calculation at the reference point with its comparison to the code, the step-size table with both slopes, and the gust table with a decision on each row.

Assessment

assessments/phase-01/grading-rubric.md; competencies 1–4. Pass: all partials and the implicit derivative derived with the held-fixed variable named at each step; all public tests pass; the hand calculation agrees with the code to four figures; the gust decision is argued from the second-order remainder with a number.

References

@openstax-calculus-volume-3 §4.1 "Functions of Several Variables" (required-free); §4.2 "Limits and Continuity" (supplementary-free, skim); §4.3 "Partial Derivatives" (required-free); §4.4 "Tangent Planes and Linear Approximations" (required-free); §4.5 "The Chain Rule" (required-free).

Extensions

★ Add density as a third variable, L(α,V,ρ)L(\alpha, V, \rho), with ρ(h)\rho(h) from P00.03, and compute ∂L/∂h\partial L/\partial h at 2 km by the chain rule. ★ Replace the cubic CLC_L by a table interpolated from @ntrs-naca-tr-824-summary-of-airfoil-data and see what happens to the finite-difference partials at the table's knots.

Time

unmeasured

1. The engineering problem

A four-seat light aircraft of 1540 kg cruises at 55 m/s with its wing at 4° angle of attack, producing 15.1 kN of lift to balance its weight. It flies into a gust. A vertical gust changes the angle of attack; a horizontal gust changes the airspeed; a real gust does both. The structures engineer needs the resulting lift increment to size the wing spar; the flight-dynamics engineer needs it to predict the bump the passengers feel. Both want a sensitivity: how many newtons per degree, how many newtons per metre per second. Both also need to know when that sensitivity is enough and when the gust is large enough that the lift must be recomputed from scratch.

Lift is a function of two variables, L(α,V)L(\alpha, V), and a sensitivity to one of them while the other is held fixed is a partial derivative. The two partials together give the total differential, which is the linear estimate of the lift change for any small combined gust. The questions this lesson answers are: how to compute partials (three ways, so they can be checked against each other), how to combine them, how big the error of the linear estimate is, and how the same tools give the trim speed at every angle of attack (a level curve of LL) and the rate of change of lift during a pull-up (the chain rule).

Success criteria, written before we start: the three ways of computing ∂L/∂α\partial L/\partial\alpha and ∂L/∂V\partial L/\partial V agree to 10−710^{-7} relative at the reference point; the error of the linear estimate over a box of gusts falls by a factor of 4 each time the box is halved; the lift along the computed trim curve is constant to 10−1210^{-12}; and the hand calculation agrees with the code to four figures.

2. Understand and derive

2.1 The lift function

Lift on a wing of area SS in air of density ρ\rho at speed VV is

L(α,V)=12ρV2S CL(α)[N],(1)L(\alpha, V) = \tfrac12\rho V^2 S\,C_L(\alpha) \quad [\mathrm{N}], \tag{1}

with CLC_L the dimensionless lift coefficient, a property of the wing's shape and orientation. Units: (kg/m³)(m²/s²)(m²) = kg m/s² = N ✓. Assumption 1 (incompressible, quasi-steady): CLC_L depends on the angle of attack α\alpha only. Assumption 2 (model for CLC_L): below stall a wing's lift coefficient is linear in α\alpha with lift-curve slope aa (about 2π2\pi per radian for a thin airfoil, reduced to a≈5a \approx 5 per radian for a finite wing of aspect ratio 7 by the downwash of its own tip vortices; Phase 10 derives both), measured from the zero-lift angle α0\alpha_0 (negative for a cambered wing). Near stall the lift rolls off. We model the whole curve as

CL(α)=a(α−α0)−k3(α−α0)3,α in radians,(2)C_L(\alpha) = a(\alpha - \alpha_0) - k_3(\alpha - \alpha_0)^3, \qquad \alpha \text{ in radians}, \tag{2}

whose maximum (stall) is where dCL/dα=a−3k3(α−α0)2=0\mathrm{d}C_L/\mathrm{d}\alpha = a - 3k_3(\alpha - \alpha_0)^2 = 0, at αs=α0+a/3k3\alpha_s = \alpha_0 + \sqrt{a/3k_3}. The numbers for our wing: S=16S = 16 m², a=5.0a = 5.0 /rad, α0=−2°\alpha_0 = -2°, k3=12k_3 = 12 /rad³, ρ=1.225\rho = 1.225 kg/m³. Then αs=19.4°\alpha_s = 19.4° and CL,max⁡=1.24C_{L,\max} = 1.24, a little high in α\alpha for a real light-aircraft wing (which stalls nearer 16°) but with the right shape; §2.9 says what that costs.

Hand calculation at the reference point α=4°\alpha = 4°, V=55V = 55 m/s: α−α0=6°=0.10472\alpha - \alpha_0 = 6° = 0.10472 rad; CL=5.0×0.10472−12×0.104723=0.52360−0.01378=0.50982C_L = 5.0 \times 0.10472 - 12 \times 0.10472^3 = 0.52360 - 0.01378 = 0.50982; dynamic pressure q=12×1.225×552=1852.8q = \tfrac12 \times 1.225 \times 55^2 = 1852.8 Pa; L=1852.8×16×0.50982=15 114L = 1852.8 \times 16 \times 0.50982 = 15\,114 N, which is 1541 kg of aircraft. Sanity: a Cessna-class four-seater at 55 m/s (107 kt) and 4° is right.

A function of two variables is a surface over the (α,V)(\alpha, V) plane (@openstax-calculus-volume-3 §4.1). The curves of constant LL on that plane are its level curves; the one through L=WL = W (weight) is the trim curve, every combination of angle of attack and speed at which the wing carries exactly the aircraft. Solving (1) for VV,

V(α)=2LρS CL(α),(3)V(\alpha) = \sqrt{\frac{2L}{\rho S\,C_L(\alpha)}}, \tag{3}

defined only where CL>0C_L > 0, and falling as α\alpha rises: more angle, less speed. At CL,max⁡C_{L,\max} it bottoms out at the stall speed, 35.235.2 m/s for our wing at 15.1 kN.

2.2 Partial derivatives

The partial derivative of LL with respect to α\alpha is the ordinary derivative of LL along a line of constant VV (@openstax-calculus-volume-3 §4.3):

∂L∂α=lim⁡h→0L(α+h,V)−L(α−h,V)2h.\frac{\partial L}{\partial\alpha} = \lim_{h \to 0}\frac{L(\alpha + h, V) - L(\alpha - h, V)}{2h}.

Everything that does not contain α\alpha is a constant, so from (1) and (2),

Lα≡∂L∂α=12ρV2S [a−3k3(α−α0)2][N/rad],(4)L_\alpha \equiv \frac{\partial L}{\partial\alpha} = \tfrac12\rho V^2 S\,\big[a - 3k_3(\alpha - \alpha_0)^2\big] \quad [\mathrm{N/rad}], \tag{4}
LV≡∂L∂V=ρVS CL(α)=2LV[N/(m/s)].(5)L_V \equiv \frac{\partial L}{\partial V} = \rho V S\,C_L(\alpha) = \frac{2L}{V} \quad [\mathrm{N/(m/s)}]. \tag{5}

(5) is worth a pause: because L∝V2L \propto V^2, LV=2L/VL_V = 2L/V whatever CLC_L is, so a 1 % increase in speed is always a 2 % increase in lift. The analogous relative sensitivity in α\alpha is Lα(α−α0)/L=[a−3k3d2]/[a−k3d2]L_\alpha(\alpha - \alpha_0)/L = [a - 3k_3 d^2]/[a - k_3 d^2] with d=α−α0d = \alpha - \alpha_0: exactly 1 for the linear model, less as stall approaches, and zero at CL,max⁡C_{L,\max}, where more angle of attack buys no lift at all.

At the reference point: dCL/dα=5.0−36×0.010966=4.6052\mathrm{d}C_L/\mathrm{d}\alpha = 5.0 - 36 \times 0.010966 = 4.6052 /rad, so Lα=1852.8×16×4.6052=136 522L_\alpha = 1852.8 \times 16 \times 4.6052 = 136\,522 N/rad =2383= 2383 N/deg, and LV=2×15 114/55=549.6L_V = 2 \times 15\,114/55 = 549.6 N/(m/s). Relative sensitivities: 0.946 in α\alpha (the cubic term is already costing 5 %) and 2.000 in VV.

2.3 Second partials and Clairaut's theorem

Differentiate again, each way:

Lαα=12ρV2S (−6k3d),LVV=ρS CL,LαV=ρVS [a−3k3d2]=LVα.(6)L_{\alpha\alpha} = \tfrac12\rho V^2 S\,(-6k_3 d), \qquad L_{VV} = \rho S\,C_L, \qquad L_{\alpha V} = \rho V S\,[a - 3k_3 d^2] = L_{V\alpha}. \tag{6}

The two mixed partials are equal: differentiating (4) in VV or (5) in α\alpha gives the same expression. That is Clairaut's theorem, true whenever the second partials are continuous (@openstax-calculus-volume-3 §4.3), and it is a test: compute LαVL_{\alpha V} by finite differences in the two orders and they must agree. At the reference point Lαα=−223 518L_{\alpha\alpha} = -223\,518 N/rad², LVV=9.992L_{VV} = 9.992 N/(m/s)², LαV=4964L_{\alpha V} = 4964 N/(rad m/s). The sign of LααL_{\alpha\alpha} is the lift curve bending over toward stall.

2.4 The total differential and the tangent plane

For a small combined change (Δα,ΔV)(\Delta\alpha, \Delta V) the first-order estimate adds the two one-variable estimates (@openstax-calculus-volume-3 §4.4):

ΔL≈dL=Lα Δα+LV ΔV.(7)\Delta L \approx \mathrm{d}L = L_\alpha\,\Delta\alpha + L_V\,\Delta V. \tag{7}

Geometrically, (7) is the tangent plane to the surface L(α,V)L(\alpha, V) at the reference point, and the surface itself lies off the plane by the second-order remainder (two-variable Taylor's theorem, P01.05 extended):

ΔL−dL=12LααΔα2+LαVΔα ΔV+12LVVΔV2+O(Δ3).(8)\Delta L - \mathrm{d}L = \tfrac12 L_{\alpha\alpha}\Delta\alpha^2 + L_{\alpha V}\Delta\alpha\,\Delta V + \tfrac12 L_{VV}\Delta V^2 + O(\Delta^3). \tag{8}

Halve both Δ\Deltas and the remainder drops by 4: that is the convergence test. For a pure speed gust the remainder is exactly 12LVVΔV2=12ρSCLΔV2\tfrac12 L_{VV}\Delta V^2 = \tfrac12\rho S C_L\Delta V^2, with no O(Δ3)O(\Delta^3), because LL is a quadratic in VV; for a pure α\alpha gust there is also a cubic term, 16LαααΔα3\tfrac16 L_{\alpha\alpha\alpha}\Delta\alpha^3 with Lααα=−6k3qSL_{\alpha\alpha\alpha} = -6k_3 qS.

The gust, by hand. Δα=+5°=0.08727\Delta\alpha = +5° = 0.08727 rad at fixed VV: linear dL=136 522×0.08727=11 914\mathrm{d}L = 136\,522 \times 0.08727 = 11\,914 N; second-order correction 12(−223 518)(0.08727)2=−851\tfrac12(-223\,518)(0.08727)^2 = -851 N; third-order 16(−6×12×1852.8×16)(0.08727)3=−236\tfrac16(-6 \times 12 \times 1852.8 \times 16)(0.08727)^3 = -236 N; total 10 82710\,827 N against the exact L(9°,55)−L0=10 826L(9°, 55) - L_0 = 10\,826 N. The linear estimate is 10 % high. ΔV=+10\Delta V = +10 m/s at fixed α\alpha: linear 54965496 N, remainder 12×9.992×100=500\tfrac12 \times 9.992 \times 100 = 500 N, exact 59955995 N: the linear estimate is 8 % low. Both together: linear 17 41017\,410 N; the remainder (8) adds −851+4964×0.08727×10+500=3981-851 + 4964 \times 0.08727 \times 10 + 500 = 3981 N plus the cubic −236-236 N, giving 21 15521\,155 N against the exact 21 11621\,116 N. The linear estimate is now 18 % low, and the cross term LαVΔαΔVL_{\alpha V}\Delta\alpha\Delta V is the biggest correction: lift from extra angle at the higher speed is worth more than either alone. That cross term is exactly what a one-variable analysis cannot see.

2.5 Implicit differentiation: the slope of the trim curve

Along the level curve L(α,V)=WL(\alpha, V) = W the two variables are tied together. Differentiate the identity L(α,V(α))=WL(\alpha, V(\alpha)) = W with the chain rule (@openstax-calculus-volume-3 §4.5):

Lα+LVdVdα=0⟹dVdα=−LαLV.(9)L_\alpha + L_V\frac{\mathrm{d}V}{\mathrm{d}\alpha} = 0 \quad\Longrightarrow\quad \frac{\mathrm{d}V}{\mathrm{d}\alpha} = -\frac{L_\alpha}{L_V}. \tag{9}

For our wing −136 522/549.6=−248.4-136\,522/549.6 = -248.4 (m/s)/rad =−4.34= -4.34 (m/s)/deg: each extra degree of angle of attack lets the aircraft fly 4.3 m/s slower at the same lift. The same number from (3) directly: dV/dα=−12V (dCL/dα)/CL=−12×55×4.6052/0.50982=−248.4\mathrm{d}V/\mathrm{d}\alpha = -\tfrac12 V\,(\mathrm{d}C_L/\mathrm{d}\alpha)/C_L = -\tfrac12 \times 55 \times 4.6052/0.50982 = -248.4 ✓. Two routes, one number, which is the test. Implicit differentiation is how you get a slope when you cannot, or would rather not, solve for V(α)V(\alpha) explicitly.

2.6 The chain rule along a manoeuvre

In a pull-up both α\alpha and VV change with time. The rate of change of lift is

dLdt=∂L∂αdαdt+∂L∂VdVdt,(10)\frac{\mathrm{d}L}{\mathrm{d}t} = \frac{\partial L}{\partial\alpha}\frac{\mathrm{d}\alpha}{\mathrm{d}t} + \frac{\partial L}{\partial V}\frac{\mathrm{d}V}{\mathrm{d}t}, \tag{10}

one term per path by which time reaches LL. For α˙=2°\dot\alpha = 2°/s and V˙=−1\dot V = -1 m/s² at the reference point: 136 522×0.034907−549.6×1=4766−550=4216136\,522 \times 0.034907 - 549.6 \times 1 = 4766 - 550 = 4216 N/s, so the load factor rises by 4216/15 114=0.28 g4216/15\,114 = 0.28\,g per second. Units: (N/rad)(rad/s) + (N/(m/s))(m/s²) = N/s ✓. Along the trim curve, V˙=(dV/dα)α˙\dot V = (\mathrm{d}V/\mathrm{d}\alpha)\dot\alpha and (10) gives zero by (9): the chain rule and implicit differentiation are the same statement.

2.7 Finite differences in several variables

A partial derivative is a one-variable derivative, so the central difference of P00.09 applies with only one coordinate perturbed:

∂f∂xi≈f(x+hei)−f(x−hei)2h,(11)\frac{\partial f}{\partial x_i} \approx \frac{f(\mathbf x + h\mathbf e_i) - f(\mathbf x - h\mathbf e_i)}{2h}, \tag{11}

truncation error 16h2 ∂3f/∂xi3\tfrac16 h^2\,\partial^3 f/\partial x_i^3, rounding error about ε∣f∣/h\varepsilon|f|/h. For ∂L/∂α\partial L/\partial\alpha, Lααα=−6k3qS=−2.134×106L_{\alpha\alpha\alpha} = -6k_3 qS = -2.134 \times 10^6 N/rad³, so at h=10−2h = 10^{-2} rad the truncation error is 16×10−4×2.134×106=35.6\tfrac16 \times 10^{-4} \times 2.134 \times 10^6 = 35.6 N/rad (relative 2.6×10−42.6 \times 10^{-4}), and it falls 100-fold per decade of hh until rounding takes over near h=10−6h = 10^{-6}. For ∂L/∂V\partial L/\partial V the third derivative is zero (LL is quadratic in VV) and the central difference is exact up to rounding at every hh: the two columns of the step-size table look completely different, and part 4 asks you to say why before you run it.

2.8 How SymPy does it

sp.diff(L, alpha) treats every other symbol as a constant, which is precisely the definition of a partial derivative; the result is (4) in symbolic form, and substituting numbers gives the same 136 521.6136\,521.6 N/rad as the hand formula. The value of the symbolic route is not the number but the structure: sp.simplify(sp.diff(L, V) - 2*L/V) returns 0, proving (5) for every CLC_L, and sp.simplify(sp.diff(L, alpha, V) - sp.diff(L, V, alpha)) returns 0, proving Clairaut for this LL without choosing a point.

2.9 Where the model stops being valid

  • Stall. The cubic (2) is a caricature. A real CL(α)C_L(\alpha) has a sharper peak, hysteresis, and depends on Reynolds number. Partials computed past about 12° for this wing are properties of the caricature, not the aircraft.
  • Compressibility. Above Mach 0.3 (about 100 m/s at sea level) CLC_L grows with Mach by roughly 1/1−M21/\sqrt{1 - M^2}, adding a VV-dependence to CLC_L that (5) ignores.
  • Unsteady flow. A sharp-edged gust takes several chord-lengths of travel (about 0.1 s here) before the lift reaches its new steady value; (7) is the steady increment.
  • Density. Lρ=L/ρL_\rho = L/\rho is the third partial we have frozen; at 2000 m the ISA density is 1.006 kg/m³ and every lift number drops 18 %. The extension adds it.

3. Build the computational model

Open starter/main.py. The wing lives in a frozen Wing dataclass so every function takes the same parameter object; the tests build their own Wing(k3=0.0) to reach the linear model.

Step 1: the function and its analytic partials

def lift_coefficient(alpha, wing=DEFAULT_WING):
    d = np.asarray(alpha, dtype=float) - wing.alpha0
    return wing.a * d - wing.k3 * d**3                                          # (2)

def lift(alpha, V, wing=DEFAULT_WING):
    V = np.asarray(V, dtype=float)
    if np.any(V < 0.0):
        raise ValueError("airspeed must be non-negative")
    return 0.5 * wing.rho * V**2 * wing.S * lift_coefficient(alpha, wing)     # (1)

def lift_partials(alpha, V, wing=DEFAULT_WING):
    d = alpha - wing.alpha0
    dcl = wing.a - 3.0 * wing.k3 * d**2
    return 0.5 * wing.rho * V**2 * wing.S * dcl, wing.rho * V * wing.S * lift_coefficient(alpha, wing)   # (4), (5)

alpha[:, None] against V[None, :] broadcasts to a full grid, which is how main() draws the level curves.

Step 2: finite-difference partials of any function

def partial_derivative(f, x, i, h):
    e = np.zeros_like(x); e[i] = h                     # perturb one coordinate only
    return float((f(x + e) - f(x - e)) / (2.0 * h))   # (11)

def mixed_partial(f, x, i, j, h):
    return partial_derivative(lambda y: partial_derivative(f, y, i, h), x, j, h)

f takes a single array argument, so the same code differentiates L(α,V)L(\alpha, V), x2yx^2 y or anything else; the tests use all three.

Step 3: SymPy, linearization, sensitivities

lift_partials_sympy builds LL from symbols and returns sp.diff(L, alpha), sp.diff(L, V) and the symbol table. lift_linearized is (7) added to LL at the reference point; relative_sensitivities returns Lα(α−α0)/LL_\alpha(\alpha - \alpha_0)/L and LVV/LL_V V/L; stall_angle is α0+a/3k3\alpha_0 + \sqrt{a/3k_3} and raises for k3=0k_3 = 0; tangent_plane_error_study evaluates max⁡∣L−Llin∣\max|L - L_{\text{lin}}| over an 11×1111 \times 11 grid in a box that shrinks with each scale.

Step 4: level curve and chain rule

def level_curve_speed(alpha, L_target, wing=DEFAULT_WING):
    cl = lift_coefficient(alpha, wing)
    if np.any(cl <= 0.0):
        raise ValueError("C_L must be positive on the level curve")
    return np.sqrt(2.0 * L_target / (wing.rho * wing.S * cl))                  # (3)

def level_curve_slope(alpha, V, wing=DEFAULT_WING):
    la, lv = lift_partials(alpha, V, wing)
    return -la / lv                                                             # (9)

def lift_rate(alpha, V, dalpha_dt, dV_dt, wing=DEFAULT_WING):
    la, lv = lift_partials(alpha, V, wing)
    return la * dalpha_dt + lv * dV_dt                                          # (10)

Verify

Run python -m pytest curriculum/phase-01/lesson-08-partial-derivatives from the repo root. The tests, in order of how much they would hurt if wrong:

  1. The function. L(2V)=4L(V)L(2V) = 4L(V); L=0L = 0 at α0\alpha_0 and at V=0V = 0; a (5,1)×(1,3)(5, 1) \times (1, 3) input gives a (5,3)(5, 3) output; negative speed raises.
  2. Three partials agree. Analytic against central differences at second order in α\alpha (rates above 1.9 as hh halves) and to 10−1010^{-10} in VV at any hh; analytic against SymPy to 10−1210^{-12}; SymPy proves LV=2L/VL_V = 2L/V and Clairaut symbolically; the finite-difference mixed partials agree in both orders and with (6).
  3. Linearization. The tangent-plane error over a shrinking box falls by 4.0±0.24.0 \pm 0.2 per halving; along VV the error is exactly 12ρSCLΔV2\tfrac12\rho S C_L\Delta V^2.
  4. Limits. With k3=0k_3 = 0 the relative sensitivities are exactly 1 and 2 and stall_angle raises; at αs\alpha_s the α\alpha-sensitivity is zero and argmax of CLC_L on a fine grid lands within 0.02° of it.
  5. Level curve and chain rule. Lift along level_curve_speed is constant to 10−1210^{-12} and the curve descends; the implicit slope matches a central difference of (3) to 10−710^{-7}; lift_rate matches a finite difference of L(α(t),V(t))L(\alpha(t), V(t)) along a quadratic manoeuvre to 10−710^{-7} and vanishes along the trim curve.
  6. Interface. main() writes the figure.

Compare

main() prints the three routes side by side:

dL/dalpha = 136521.6 N/rad = 2382.8 N/deg;  dL/dV = 549.6 N/(m/s)
central differences h = 1e-02: dL/dalpha err 3.56e+01 N/rad, dL/dV err 2.17e-10 N/(m/s)
central differences h = 1e-03: dL/dalpha err 3.56e-01 N/rad, dL/dV err 1.22e-09 N/(m/s)
central differences h = 1e-04: dL/dalpha err 3.56e-03 N/rad, dL/dV err 1.70e-08 N/(m/s)
sympy: dL/dalpha = 136521.6, dL/dV = 549.6
mixed partials: L_alpha_V = 4964.410, L_V_alpha = 4964.410 N/(rad m/s)

The α\alpha column falls exactly 100-fold per decade, and 35.635.6 N/rad at h=10−2h = 10^{-2} is the predicted 16h2∣Lααα∣\tfrac16 h^2|L_{\alpha\alpha\alpha}| to three figures: the finite-difference error is not noise, it is a number you can compute in advance. The VV column is rounding only, growing as hh shrinks, as §2.7 said. SymPy's diff and the hand formula agree to all printed digits because they are the same algebra. The one established library in play is SymPy; there is no NumPy "partial derivative" to call, which is why partial_derivative is yours and why its error must be understood rather than trusted.

4. Experiment at home, or investigate real data

Mode: computational experiment.

Experiment A: step-size study. For h=10−1,10−2,…,10−8h = 10^{-1}, 10^{-2}, \dots, 10^{-8} (radians for α\alpha, m/s for VV), record partial_derivative(f, x0, 0, h) and partial_derivative(f, x0, 1, h) against the analytic values at the reference point. Prediction, written before running: the α\alpha error follows 16h2∣Lααα∣=3.56×105h2\tfrac16 h^2|L_{\alpha\alpha\alpha}| = 3.56 \times 10^5 h^2 N/rad down to a minimum near hopt=(3ε∣L∣/∣Lααα∣)1/3≈2×10−6h_{\text{opt}} = (3\varepsilon|L|/|L_{\alpha\alpha\alpha}|)^{1/3} \approx 2 \times 10^{-6} and then rises as ε∣L∣/h\varepsilon|L|/h; the VV error has no h2h^2 branch and is at the rounding floor (∼10−10\sim 10^{-10}) for every hh above 10−510^{-5}. Plot both on log–log axes, fit the slopes on each side of the minimum, and save as fd_partials_vs_h.png.

Experiment B: map of the tangent-plane error. On a grid Δα∈[−6°,6°]\Delta\alpha \in [-6°, 6°], ΔV∈[−15,15]\Delta V \in [-15, 15] m/s around the reference point, compute L−LlinL - L_{\text{lin}} and the second-order prediction (8). Prediction: the error is dominated by the cross term, so it is positive when Δα\Delta\alpha and ΔV\Delta V have the same sign and negative otherwise, and (8) reproduces it to within the cubic term 16LαααΔα3\tfrac16 L_{\alpha\alpha\alpha}\Delta\alpha^3 (≤410\le 410 N at 6°6°). Contour the error and mark the region where ∣L−Llin∣<2|L - L_{\text{lin}}| < 2 % of L0L_0: that is the region in which the sensitivity estimate is good enough.

Raw data format: two tables, (h,errα,errV)(h, \text{err}_\alpha, \text{err}_V) and (Δα,ΔV,ΔLexact,dL,remainder)(\Delta\alpha, \Delta V, \Delta L_{\text{exact}}, \mathrm{d}L, \text{remainder}), kept in your lesson notes.

5. Validate and improve

Hand (§2), code and the independent route side by side at the reference point:

quantity hand code (analytic) independent check difference
LL (N) 15 114 15 113.6 0
LαL_\alpha (N/rad) 136 522 136 521.6 FD h=10−4h = 10^{-4}: 136 521.62; SymPy 136 521.6 3×10−83 \times 10^{-8}
LVL_V (N/(m/s)) 549.6 549.58 2L/V=549.582L/V = 549.58; FD exact 10−1210^{-12}
LαVL_{\alpha V} (N/(rad m/s)) 4964 4964.42 FD both orders 4964.41 2.6×10−62.6 \times 10^{-6}
dV/dα\mathrm{d}V/\mathrm{d}\alpha ((m/s)/rad) −248.4-248.4 −248.41-248.41 FD of (3): −248.41-248.41 10−810^{-8}
gust +5°+5°: ΔL\Delta L (N) 10 827 (to 3rd order) 10 826 (exact) linear 11 914 linear 10 % high
gust +10+10 m/s: ΔL\Delta L (N) 5995 (to 2nd order, exact) 5995 linear 5496 linear 8 % low
both: ΔL\Delta L (N) 21 155 (to 3rd order) 21 116 linear 17 410 linear 18 % low

Every residual has a cause. The 10−810^{-8} on LαL_\alpha is the h2h^2 truncation at h=10−4h = 10^{-4}, predicted by §2.7. The 2.6×10−62.6 \times 10^{-6} on the mixed partial is the same truncation applied twice (the inner difference in α\alpha at h=10−3h = 10^{-3}). The 39 N gap between the third-order hand estimate and the exact combined gust is the fourth-order cross terms, 12LααVΔα2ΔV\tfrac12 L_{\alpha\alpha V}\Delta\alpha^2\Delta V and friends, which (8) drops: LL is cubic in α\alpha and quadratic in VV, so its Taylor series terminates at fifth order and you could, in principle, write the gust response exactly as a polynomial. The 10 %, 8 % and 18 % errors of the linear estimate are the engineering content: for a 1°1° or 11 m/s gust the linear estimate is within 0.3 %, for a 5°5° and 1010 m/s gust it is wrong by a fifth, and the cross term is the main reason.

What is still unverified when everything agrees: the lift model. The three routes to LαL_\alpha agree because they differentiate the same (2); a wind-tunnel CL(α)C_L(\alpha) for this wing at this Reynolds number would differ from the cubic by several percent above 10°, and that uncertainty, not the 10−810^{-8} of the arithmetic, is the precision of any gust load computed here. Phase 10 replaces (2) with a computed lift curve; @ntrs-naca-tr-824-summary-of-airfoil-data has measured ones.

Improvements worth making now: use the second-order estimate (8) rather than (7) for gusts above about 2°, since the Hessian costs three more numbers and removes most of the error; or, simplest of all, evaluate LL at the gust point directly, which is cheap for a formula but is not an option when "the function" is a two-hour CFD run, which is when sensitivities earn their keep. Improvements worth not making: pushing hh below 10−610^{-6} to "get more digits"; part 4 shows what happens.

6. Defend your work

Submit: the completed starter/main.py with all tests passing; lift_sensitivity.png and fd_partials_vs_h.png; the hand calculation with its comparison table; the two experiment tables with one paragraph each; and a one-page note (sections 1, 2, 5, 6 and 7 of projects/_template/report-template.md) stating for which gust sizes the linear sensitivity is adequate and why.

Adversarial self-checks

  • What if the speed doubles? LL quadruples, LαL_\alpha quadruples, LVL_V doubles, and the relative sensitivities do not change at all. Check with the code; if LVL_V quadruples you have differentiated V2V^2 as V2V^2.
  • What if V→0V \to 0? What if α→αs\alpha \to \alpha_s? At V=0V = 0 both partials vanish and the level curve (3) runs off to infinite speed as CL→0C_L \to 0; at αs\alpha_s, Lα=0L_\alpha = 0, the implicit slope (9) is zero (the trim curve is horizontal: stall speed), and the relative α\alpha-sensitivity is zero.
  • Which assumption fails first in the real world? The cubic stall model, as soon as a gust takes α\alpha past about 12°; then quasi-steadiness for gusts shorter than a tenth of a second; compressibility only above 100 m/s.
  • What measurement could falsify the model? A wind-tunnel lift curve: if the measured dCL/dα\mathrm{d}C_L/\mathrm{d}\alpha at 4° is not within a few percent of 4.6 /rad, every sensitivity here is off by the same factor. A flight test with an accelerometer through a known gust gives ΔL\Delta L directly.
  • Does the result survive a change in step size? LαL_\alpha by finite difference must agree to 10−610^{-6} for any hh between 10−510^{-5} and 10−310^{-3}. If your answer depends on hh in that range, the function you are differentiating is not smooth (a table with kinks, a clipped CLC_L) and no finite-difference partial is meaningful there.
  • Which decision changes if the uncertainty doubled? Suppose aa is known to ±10 % instead of ±5 %. The +5°+5° gust load is then 10 826±108310\,826 \pm 1083 N instead of ±541 N; a spar designed with a 1.5 safety factor on 15.1 kN has 7.5 kN of margin either way, so the structure does not change, but a stall-warning margin set at 2° above the predicted α\alpha for a given speed now has to be 3°. The decision that moves is the one with the smaller margin.

Check yourself

  1. Write ∂L/∂V\partial L/\partial V for L=12ρV2SCL(α)L = \tfrac12\rho V^2 S C_L(\alpha) and say why it does not depend on the form of CLC_L.
  2. What is held fixed when you compute ∂L/∂α\partial L/\partial\alpha, and what would be different about dL/dα\mathrm{d}L/\mathrm{d}\alpha along the trim curve?
  3. State Clairaut's theorem for L(α,V)L(\alpha, V) and the condition under which it holds.
  4. The total differential dL=LαΔα+LVΔV\mathrm{d}L = L_\alpha\Delta\alpha + L_V\Delta V misses one second-order term that the two single-variable estimates cannot see. Which one?
  5. Along the level curve L=WL = W, what is dV/dα\mathrm{d}V/\mathrm{d}\alpha in terms of the partials, and what is its sign below stall?
  6. For a 1 % increase in airspeed, by what percentage does lift change? For a 1 % increase in α−α0\alpha - \alpha_0 in the linear model?
  7. Why does the central difference of ∂L/∂V\partial L/\partial V show no h2h^2 error while that of ∂L/∂α\partial L/\partial\alpha does?
  8. In a pull-up, α\alpha increases at 2°/s and VV decreases at 1 m/s². Write dL/dt\mathrm{d}L/\mathrm{d}t with its units and say which term dominates for the lesson's wing.

Problem set

Attempt every problem before opening solutions/. Record what you tried. State units on every numerical answer and name the variable held fixed in every partial derivative you write.

Several problems use your personal seed s: the day of the month you were born (1–31). ρ=1.225\rho = 1.225 kg/m³ and g=9.80665g = 9.80665 m/s² unless stated.

1. (Warm-up: a linear wing)

A wing has S=10+0.2sS = 10 + 0.2s m², lift-curve slope a=4.5+0.02sa = 4.5 + 0.02s per radian, zero-lift angle α0=−2°\alpha_0 = -2° and no stall roll-off (k3=0k_3 = 0). It flies at V=50V = 50 m/s and α=5°\alpha = 5°.

Find: (a) CLC_L and LL; (b) ∂L/∂α\partial L/\partial\alpha in N/rad and N/deg, and ∂L/∂V\partial L/\partial V; (c) the lift increments for +1°+1° alone, for +1+1 m/s alone, and for both, first from the total differential and then exactly; (d) the percentage error of the total differential in each case. Check (a)–(c) with lift, lift_partials and lift_linearized using Wing(S=..., a=..., k3=0.0). Answer form: numbers with units, four significant figures.

2. (Derivation: the calculus of the lift function)

For L=12ρV2S CL(α)L = \tfrac12\rho V^2 S\,C_L(\alpha) with CL=a(α−α0)−k3(α−α0)3C_L = a(\alpha - \alpha_0) - k_3(\alpha - \alpha_0)^3:

(a) Derive LαL_\alpha, LVL_V, LααL_{\alpha\alpha}, LVVL_{VV}, LαVL_{\alpha V} and LVαL_{V\alpha} and confirm the last two are equal. (b) Show that along the level curve L=WL = W, dV/dα=−12V CL′(α)/CL(α)\mathrm{d}V/\mathrm{d}\alpha = -\tfrac12 V\,C_L'(\alpha)/C_L(\alpha) in two ways: by implicit differentiation of L(α,V(α))=WL(\alpha, V(\alpha)) = W, and by differentiating the explicit V(α)=2W/(ρSCL)V(\alpha) = \sqrt{2W/(\rho S C_L)}. (c) Show that for a pure speed change ΔV\Delta V at fixed α\alpha the tangent-plane error is exactly 12ρSCL ΔV2\tfrac12\rho S C_L\,\Delta V^2 (no higher-order terms), and that for a pure α\alpha change it is 12LααΔα2+16LαααΔα3\tfrac12 L_{\alpha\alpha}\Delta\alpha^2 + \tfrac16 L_{\alpha\alpha\alpha}\Delta\alpha^3 exactly. (d) Write the second-order two-variable Taylor remainder (8) and use (a) to show that the cross term LαVΔαΔVL_{\alpha V}\Delta\alpha\Delta V equals 2 dLα ΔV/V2\,\mathrm{d}L_\alpha\,\Delta V/V, where dLα=LαΔα\mathrm{d}L_\alpha = L_\alpha\Delta\alpha is the linear α\alpha-increment. Interpret the factor 2ΔV/V2\Delta V/V.

Answer form: derivations with each held-fixed variable named.

3. (Unfamiliar scenario: airspeed from a Pitot tube, with uncertainty)

An airspeed indicator computes V=2q/ρV = \sqrt{2q/\rho} from the measured dynamic pressure qq and an assumed density ρ\rho. On one flight q=1500±15q = 1500 \pm 15 Pa and ρ=1.225±0.020\rho = 1.225 \pm 0.020 kg/m³ (independent, one standard deviation each).

(a) Compute VV and the partials ∂V/∂q\partial V/\partial q and ∂V/∂ρ\partial V/\partial\rho with units. (b) Propagate the two uncertainties with the total differential in quadrature: δV2=(Vqδq)2+(Vρδρ)2\delta V^2 = (V_q\delta q)^2 + (V_\rho\delta\rho)^2. Which input dominates? (c) Show that the relative sensitivities are ∂ln⁡V/∂ln⁡q=12\partial\ln V/\partial\ln q = \tfrac12 and ∂ln⁡V/∂ln⁡ρ=−12\partial\ln V/\partial\ln\rho = -\tfrac12, and redo (b) in percentages. (d) On a hot day at a high airfield the density is 15 % below the assumed value and the pilot flies by indicated airspeed (the VV the instrument shows for the assumed ρ\rho). Is the true airspeed higher or lower than indicated, by what percentage, and does the lift at a given indicated airspeed change? (Use L=12ρV2SCL=qSCLL = \tfrac12\rho V^2 S C_L = qSC_L.)

Answer form: one speed, two partials, one uncertainty with the dominant term named, two percentages, one short argument.

4. (Numerical, uses your code: the step-size study)

Run Experiment A of lesson part 4 for the reference point (α=4°\alpha = 4°, V=55V = 55 m/s, default Wing).

(a) Tabulate the errors of partial_derivative in α\alpha and in VV for h=10−1,…,10−8h = 10^{-1}, \dots, 10^{-8} and plot them on log–log axes. (b) Fit the slope of the α\alpha error for h≥10−4h \ge 10^{-4} and for h≤10−7h \le 10^{-7}; compare the large-hh branch with the predicted 16h2∣Lααα∣\tfrac16 h^2|L_{\alpha\alpha\alpha}| using Lααα=−6k3qSL_{\alpha\alpha\alpha} = -6k_3 qS. (c) Explain the VV column: why is there no sloped branch on the left, and at what hh does rounding become visible? (d) Repeat (a) for the mixed partial with mixed_partial in both orders and report the largest hh at which they agree to 10−610^{-6} relative.

Answer form: a table, a plot, two slopes, one comparison, two short explanations.

5. (Judgment: where the linear sensitivity stops)

For each situation, say whether the total differential (7) is adequate (error below 2 % of L0L_0), and if not what you would use instead; give the number that decides:

(a) a 2°2° vertical gust at the reference point; (b) a 6°6° vertical gust with a simultaneous 1212 m/s headwind gust; (c) a 4°4° gust at α=14°\alpha = 14°, close to the model's stall; (d) the same 2°2° gust during a descent at 95 m/s at sea level (hint: Mach number).

Answer form: four verdicts, each with a number and one sentence.

6. (Hard: lift through altitude, the chain rule with three variables)

Let density depend on altitude through the ISA troposphere, ρ(h)=ρ0(1−2.2558×10−5h)4.2559\rho(h) = \rho_0(1 - 2.2558 \times 10^{-5}h)^{4.2559} with hh in metres and ρ0=1.225\rho_0 = 1.225 kg/m³ (P00.03), so that L=L(α,V,ρ(h))L = L(\alpha, V, \rho(h)).

(a) Write ∂L/∂ρ\partial L/\partial\rho and dρ/dh\mathrm{d}\rho/\mathrm{d}h, and evaluate both at h=2000h = 2000 m. (b) The aircraft climbs at h˙=5\dot h = 5 m/s with α=4°\alpha = 4° and V=55V = 55 m/s held constant. Compute dL/dt\mathrm{d}L/\mathrm{d}t by the chain rule and check it against a central difference of L(α,V,ρ(h(t)))L(\alpha, V, \rho(h(t))) in tt. (c) To hold the lift constant during the climb the pilot must raise α\alpha. Find the required α˙\dot\alpha in degrees per second from Lαα˙+Lρρ˙=0L_\alpha\dot\alpha + L_\rho\dot\rho = 0, and the altitude at which α\alpha would reach the model's stall angle if VV stays at 55 m/s. (d) Add the time derivative of VV as a third term. If the climb also bleeds speed at V˙=−0.1\dot V = -0.1 m/s², which of the two terms dominates dL/dt\mathrm{d}L/\mathrm{d}t, by what factor, and what α˙\dot\alpha is now needed to hold the lift? State in one sentence what the chain rule is doing in this problem that a single-variable derivative could not.

Answer form: two expressions with values, one rate with its finite-difference check, two α˙\dot\alpha values and one altitude, one factor, one sentence.

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-01/lesson-08-partial-derivatives

To run the same tests against the reference solution instead:

AEFS_IMPL=solution pytest curriculum/phase-01/lesson-08-partial-derivatives

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