TExcelTAD
Home › Calculus in Depth › Tangent Planes and Linear Approximations

Tangent Planes and Linear Approximations

Zoom in far enough on a smooth surface and it looks flat: it becomes its tangent plane. The tangent plane gives the best linear approximation of a function of several variables, and that linearisation is the workhorse behind error propagation, Newton-type solvers and every first-order optimiser. This lesson defines differentiability properly, shows that partial derivatives alone are not enough, and proves when they are.

The one-variable version is Linear Approximations and Differentials.

The tangent plane

Suppose ff has continuous partial derivatives near (a,b)(a, b). The tangent plane to z=f(x,y)z = f(x, y) at P=(a,b,f(a,b))P = (a, b, f(a, b)) is

z−f(a,b)=fx(a,b)(x−a)+fy(a,b)(y−b)z - f(a, b) = f_x(a, b)(x - a) + f_y(a, b)(y - b)

Why this plane: it passes through PP, and its traces in the planes y=by = b and x=ax = a are lines with slopes fx(a,b)f_x(a, b) and fy(a,b)f_y(a, b), the tangent lines of the two partial-derivative traces. A normal vector is ⟨fx(a,b),fy(a,b),−1⟩\langle f_x(a, b), f_y(a, b), -1 \rangle.

Example: f(x,y)=4−x2−2y2f(x, y) = 4 - x^2 - 2y^2 at (1,1)(1, 1), where f=1f = 1, fx=−2x=−2f_x = -2x = -2, fy=−4y=−4f_y = -4y = -4:

z−1=−2(x−1)−4(y−1)  ⟺  z=7−2x−4yz - 1 = -2(x - 1) - 4(y - 1) \qquad \iff \qquad z = 7 - 2x - 4y

Linearisation

The linear function whose graph is the tangent plane is the linearisation of ff at (a,b)(a, b):

L(x,y)=f(a,b)+fx(a,b)(x−a)+fy(a,b)(y−b)f(x,y)≈L(x,y)for (x,y) near (a,b)\begin{aligned} L(x, y) &= f(a, b) + f_x(a, b)(x - a) + f_y(a, b)(y - b) \\ f(x, y) &\approx L(x, y) \quad \text{for } (x, y) \text{ near } (a, b) \end{aligned}

In vector form, with p=(a,b)p = (a, b) and a small step Δ\Delta, f(p+Δ)≈f(p)+∇f(p)⋅Δf(p + \Delta) \approx f(p) + \nabla f(p) \cdot \Delta. This is the first-order Taylor polynomial in two variables; adding the second-order (Hessian) term gives the quadratic approximation used in the second-derivative test.

python · try it yourself
import numpy as np

f = lambda x, y: np.sqrt(x**2 + 3 * y**2)
a, b = 2.0, 1.0
fa = f(a, b)                                     # √7
fx, fy = a / fa, 3 * b / fa
L = lambda x, y: fa + fx * (x - a) + fy * (y - b)

print(f"f(2,1) = {fa:.6f},  f_x = {fx:.6f},  f_y = {fy:.6f}")
for d in [0.5, 0.1, 0.01, 0.001]:
    x, y = a + d, b - d
    err = abs(f(x, y) - L(x, y))
    dist = np.hypot(d, d)
    print(f"step {d:<6} error {err:.3e}   error/dist {err / dist:.3e}")
f(2,1) = 2.645751,  f_x = 0.755929,  f_y = 1.133893
step 0.5    error 1.890e-01   error/dist 2.673e-01
step 0.1    error 7.385e-03   error/dist 5.222e-02
step 0.01   error 7.300e-05   error/dist 5.162e-03
step 0.001  error 7.290e-07   error/dist 5.155e-04

The error divided by the distance of the step goes to 0: that ratio is exactly what differentiability demands.

Differentiability

In one variable, "the derivative exists" already means "the tangent line approximates well". In two variables, partial derivatives only look along two lines, so we need a stronger definition.

Definition. ff is differentiable at (a,b)(a, b) if fx(a,b)f_x(a, b), fy(a,b)f_y(a, b) exist and

f(a+Δx,b+Δy)=f(a,b)+fx Δx+fy Δy+ε1Δx+ε2Δyf(a + \Delta x, b + \Delta y) = f(a, b) + f_x\,\Delta x + f_y\,\Delta y + \varepsilon_1 \Delta x + \varepsilon_2 \Delta y

where ε1,ε2→0\varepsilon_1, \varepsilon_2 \to 0 as (Δx,Δy)→(0,0)(\Delta x, \Delta y) \to (0, 0). Equivalently, [f(p+Δ)−L(p+Δ)]/∥Δ∥→0[f(p + \Delta) - L(p + \Delta)] / \lVert \Delta \rVert \to 0.

Partials can exist without differentiability. Take f(x,y)=xy/(x2+y2)f(x, y) = xy/(x^2 + y^2) with f(0,0)=0f(0, 0) = 0. On both axes f=0f = 0, so fx(0,0)=fy(0,0)=0f_x(0, 0) = f_y(0, 0) = 0 and the candidate tangent plane is z=0z = 0. But along y=xy = x, f=1/2f = 1/2 everywhere except the origin: ff is not even continuous at (0,0)(0, 0), let alone approximated by z=0z = 0. A differentiable function is always continuous (let Δ→0\Delta \to 0 in the definition), so ff is not differentiable.

Theorem. If fxf_x and fyf_y exist near (a,b)(a, b) and are continuous at (a,b)(a, b), then ff is differentiable at (a,b)(a, b).

Proof sketch. Go from (a,b)(a, b) to (a+Δx,b+Δy)(a + \Delta x, b + \Delta y) in two legs: first change xx, then yy. On each leg apply the one-variable Mean Value Theorem:

f(a+Δx,b+Δy)−f(a,b)=[f(a+Δx,b+Δy)−f(a,b+Δy)]+[f(a,b+Δy)−f(a,b)]=fx(u,b+Δy) Δx+fy(a,v) Δy(u between a and a+Δx, v between b and b+Δy)\begin{aligned} &f(a + \Delta x, b + \Delta y) - f(a, b) \\ &\quad = [f(a + \Delta x, b + \Delta y) - f(a, b + \Delta y)] + [f(a, b + \Delta y) - f(a, b)] \\ &\quad = f_x(u, b + \Delta y)\,\Delta x + f_y(a, v)\,\Delta y && \text{($u$ between $a$ and $a + \Delta x$, $v$ between $b$ and $b + \Delta y$)} \end{aligned}

Set ε1=fx(u,b+Δy)−fx(a,b)\varepsilon_1 = f_x(u, b + \Delta y) - f_x(a, b) and ε2=fy(a,v)−fy(a,b)\varepsilon_2 = f_y(a, v) - f_y(a, b). Both points tend to (a,b)(a, b), so continuity of the partials gives ε1,ε2→0\varepsilon_1, \varepsilon_2 \to 0.

This is why, in practice, we check that the partial derivatives are continuous (true for any expression built from polynomials, exp, sin, ln … on their domains) and then use the tangent plane freely.

Differentials

Write dx=Δxdx = \Delta x, dy=Δydy = \Delta y for independent increments. The total differential is

dz=fx dx+fy dydz = f_x\,dx + f_y\,dy

It is the change in the linearisation, and approximates the true change Δz=f(a+dx,b+dy)−f(a,b)\Delta z = f(a + dx, b + dy) - f(a, b). For three variables, dw=fx dx+fy dy+fz dzdw = f_x\,dx + f_y\,dy + f_z\,dz.

Error propagation. A cylindrical tank is measured as r=1.5 mr = 1.5\ \text{m} and h=4 mh = 4\ \text{m}, each with error up to 0.01 m0.01\ \text{m}. V=πr2hV = \pi r^2 h, so

dV=2πrh dr+πr2 dh≤2π(1.5)(4)(0.01)+π(2.25)(0.01)≈0.377+0.071=0.448 m3dV = 2\pi rh\,dr + \pi r^2\,dh \le 2\pi(1.5)(4)(0.01) + \pi(2.25)(0.01) \approx 0.377 + 0.071 = 0.448\ \text{m}^3

against V≈28.27 m3V \approx 28.27\ \text{m}^3: a relative error of about 1.6%. Dividing by VV gives the handy rule dV/V=2 dr/r+dh/hdV/V = 2\,dr/r + dh/h: relative errors add, weighted by the exponents.

python · try it yourself
import numpy as np

V = lambda r, h: np.pi * r**2 * h
r, h, e = 1.5, 4.0, 0.01

dV = 2 * np.pi * r * h * e + np.pi * r**2 * e
worst = max(abs(V(r + s1 * e, h + s2 * e) - V(r, h)) for s1 in (-1, 1) for s2 in (-1, 1))
print(f"V = {V(r, h):.4f} m^3")
print(f"differential bound dV = {dV:.4f} m^3  ({dV / V(r, h):.2%})")
print(f"worst corner, exact    = {worst:.4f} m^3")
V = 28.2743 m^3
differential bound dV = 0.4477 m^3  (1.58%)
worst corner, exact    = 0.4499 m^3

The differential misses the exact worst case only by second-order terms (products of two errors), here about 0.002 m30.002\ \text{m}^3.

Tangent planes to level surfaces

For a surface given implicitly as F(x,y,z)=kF(x, y, z) = k, the tangent plane at PP has normal ∇F(P)\nabla F(P) (proved in Directional Derivatives and the Gradient Vector):

Fx(P)(x−x0)+Fy(P)(y−y0)+Fz(P)(z−z0)=0F_x(P)(x - x_0) + F_y(P)(y - y_0) + F_z(P)(z - z_0) = 0

The graph z=f(x,y)z = f(x, y) is the special case F=f(x,y)−z=0F = f(x, y) - z = 0, whose gradient is ⟨fx,fy,−1⟩\langle f_x, f_y, -1 \rangle, matching the normal above.

In software

  • First-order optimisers (gradient descent, SGD, Adam) work with the linearisation L(w+Δ)=L(w)+∇L⋅ΔL(w + \Delta) = L(w) + \nabla L \cdot \Delta and pick Δ\Delta to decrease it; the learning rate limits Δ\Delta to the region where the linear model is trustworthy. See Gradient Descent.
  • Gauss–Newton and Kalman filters linearise a nonlinear model around the current estimate using its Jacobian, the matrix of partial derivatives; the extended Kalman filter in robot localisation and GPS is exactly "replace ff by its tangent plane".
  • Uncertainty propagation. Physics, metrology and finance code estimate output error with σf2≈fx2σx2+fy2σy2\sigma_f^2 \approx f_x^2 \sigma_x^2 + f_y^2 \sigma_y^2 for independent inputs, the differential with errors combined in quadrature.
  • Normals for lighting. A heightmap z=f(x,y)z = f(x, y) is shaded with the normal ⟨−fx,−fy,1⟩\langle -f_x, -f_y, 1 \rangle (the same direction as ⟨fx,fy,−1⟩\langle f_x, f_y, -1 \rangle, flipped to point up), estimated from neighbouring samples.

Exercises

Exercise 1: Tangent plane

Find the tangent plane to z=xexyz = x e^{xy} at (1,0)(1, 0).

Answer

z=x+yz = x + y (through (1,0,1)(1, 0, 1)).

Solution
f(1,0)=1fx=exy+xy exy→1fy=x2exy→1z−1=1(x−1)+1(y−0)  ⟺  z=x+y\begin{aligned} f(1, 0) &= 1 \\ f_x &= e^{xy} + xy\,e^{xy} \to 1 \\ f_y &= x^2 e^{xy} \to 1 \\ z - 1 &= 1(x - 1) + 1(y - 0) \iff z = x + y \end{aligned}

Exercise 2: Linear estimate

Use a linearisation of f(x,y)=x2+y2f(x, y) = \sqrt{x^2 + y^2} at (3,4)(3, 4) to estimate 3.022+3.972\sqrt{3.02^2 + 3.97^2}, and compare with the true value.

Answer

Estimate 4.988; true value ≈4.98812\approx 4.98812.

Solution
f(3,4)=5,fx=x/f=0.6,fy=y/f=0.8L=5+0.6(0.02)+0.8(−0.03)=5+0.012−0.024=4.988\begin{aligned} &f(3, 4) = 5, \quad f_x = x/f = 0.6, \quad f_y = y/f = 0.8 \\ &L = 5 + 0.6(0.02) + 0.8(-0.03) = 5 + 0.012 - 0.024 = 4.988 \end{aligned}
python · try it yourself
import math
print(round(math.hypot(3.02, 3.97), 6))
4.988116

Exercise 3: Relative error

The power dissipated in a resistor is P=V2/RP = V^2/R. If VV is measured with relative error 1% and RR with 2%, estimate the largest relative error in PP.

Answer

About 4%.

Solution
ln⁡P=2ln⁡V−ln⁡RdP/P=2 dV/V−dR/R∣dP/P∣≤2(0.01)+0.02=0.04\begin{aligned} \ln P &= 2\ln V - \ln R \\ dP/P &= 2\,dV/V - dR/R \\ \lvert dP/P \rvert &\le 2(0.01) + 0.02 = 0.04 \end{aligned}

Exercise 4: Not differentiable (code)

For f(x,y)=xy3f(x, y) = \sqrt[3]{xy} (with f=0f = 0 when xy=0xy = 0), fx(0,0)=fy(0,0)=0f_x(0, 0) = f_y(0, 0) = 0. Compute f(t,t)/(2 t)f(t, t)/(\sqrt{2}\,t) for t=0.1,0.01,0.001t = 0.1, 0.01, 0.001. What does it show?

Answer

The ratios are about 1.52, 3.28, 7.07 and grow without bound, so [f−L]/∥Δ∥[f - L]/\lVert \Delta \rVert does not tend to 0: ff is not differentiable at the origin even though both partials exist.

Solution

The candidate linearisation is L=0L = 0, and the step (t,t)(t, t) has length 2 t\sqrt{2}\,t, so the ratio f(t,t)/(2 t)=t2/3/(2 t)=1/(2 t1/3)→∞f(t, t)/(\sqrt{2}\,t) = t^{2/3}/(\sqrt{2}\,t) = 1/(\sqrt{2}\,t^{1/3}) \to \infty.

python · try it yourself
for t in [0.1, 0.01, 0.001]:
    f = (t * t) ** (1 / 3)
    print(t, round(f / (2 ** 0.5 * t), 4))
0.1 1.5234
0.01 3.2821
0.001 7.0711

Test yourself

The tangent plane to z=f(x,y)z = f(x, y) at (a,b)(a, b) has which normal vector?

  1. ⟨fx,fy,1⟩\langle f_x, f_y, 1 \rangle evaluated anywhere
  2. ⟨a,b,f(a,b)⟩\langle a, b, f(a, b) \rangle
  3. ⟨fx(a,b),fy(a,b),−1⟩\langle f_x(a, b), f_y(a, b), -1 \rangle
  4. ⟨1,1,−1⟩\langle 1, 1, -1 \rangle

Which statement is true?

  1. If fxf_x and fyf_y exist at a point, ff is differentiable there
  2. If fxf_x and fyf_y are continuous near a point, ff is differentiable there
  3. Every continuous function is differentiable
  4. Differentiable functions can be discontinuous

For V=πr2hV = \pi r^2 h, a 1% error in rr and a 1% error in hh give a relative error in VV of about…

  1. 1%
  2. 2%
  3. 4%
  4. 3%