Maths for Machines
0 of 9 lessons done100 questions

Lesson 1 of 9

Partial derivatives: one direction at a time

For a function with many inputs, a partial derivative changes one input while temporarily freezing the others.

Core lesson · about 6 minutes · 3 guided parts

On a hill, you can ask how steep it is east–west while refusing to move north–south. That one-direction slope is a partial derivative.

Your learning route

Build the idea one piece at a time

  1. Slices through a surface
  2. Level sets and local linear models
  3. How a weather map predicts temperature a short walk away
Partial derivatives: one direction at a time, made visible
the gradient points uphill; learning steps downhill

Slices through a surface

Freeze y and slice the surface. The slice is an ordinary curve, so its slope is ∂f/∂x.

For z=f(x,y), ∂f/∂x treats y as a constant and ∂f/∂y treats x as a constant.

Partials carry units. If f is temperature and x is kilometres east, ∂f/∂x is temperature change per eastward kilometre.

Mixed partials such as ∂²f/∂y∂x measure how one directional slope changes in another direction. For smooth functions, the order usually agrees.

Holding y fixed describes a mathematical slice through the surface, not a claim that y can always be frozen in the physical system being modelled.

The symbol ∂ distinguishes a partial derivative from a one-variable derivative and reminds us which coordinate is allowed to move in that calculation.

Having every partial derivative at a point does not alone guarantee a good tangent plane; differentiability requires the combined error to be small in every approaching direction.

In symbolsfₓ=∂f/∂x, fᵧ=∂f/∂y

Worked example

For f(x,y)=x²y+3y², find fₓ and fᵧ at (2,1).

  1. Hold y fixed: fₓ=2xy.
  2. At (2,1), fₓ=2·2·1=4.
  3. Hold x fixed: fᵧ=x²+6y.
  4. At (2,1), fᵧ=4+6=10.

Answer: fₓ(2,1)=4 and fᵧ(2,1)=10

Level sets and local linear models

A contour map joins points with equal output. Zoom in near a smooth point and the surface looks like a tilted plane.

A level set f(x,y)=c is a curve of constant output, like an elevation contour or equal-loss line.

The tangent-plane approximation is f(a+Δx,b+Δy)≈f(a,b)+fₓΔx+fᵧΔy.

This total differential combines small changes from every input and is often the quickest way to estimate sensitivity or propagated measurement error.

Along a level curve, the first-order change df is zero, so its tangent movements balance the coordinate contributions f_x dx and f_y dy.

The tangent plane uses information at one base point and ignores quadratic terms, making its error usually much smaller for a move of one metre than one kilometre.

For measured inputs with small uncertainties, absolute derivative values times input uncertainties provide a cautious first-order estimate of possible output uncertainty.

In symbolsdf≈fₓdx+fᵧdy

Worked example

Use a linear approximation for f(x,y)=xy near (2,3) to estimate f(2.01,2.98).

  1. At (2,3), f=6, fₓ=y=3, and fᵧ=x=2.
  2. The input changes are Δx=0.01 and Δy=−0.02.
  3. The predicted change is 3(0.01)+2(−0.02)=−0.01.
  4. So f≈6−0.01=5.99; the exact product is 5.9898.

Answer: Approximately 5.99

Practical deep dive for this lesson

How a weather map predicts temperature a short walk away

A temperature field depends on east-west and north-south position together. Partial derivatives separate those directions, while the tangent plane recombines them for a nearby prediction.

Let T(x,y) be temperature in degrees Celsius, where x kilometres points east and y kilometres points north from a weather station.

The partial derivative Tₓ asks how temperature changes during an eastward move while north-south position is temporarily held fixed.

Likewise Tᵧ measures change per northward kilometre while x stays fixed. These are two different slopes through the same surface.

A contour line joins locations with equal temperature. Walking along it changes x and y in a combination whose first-order temperature changes cancel.

Near a measured point, the curved temperature surface is approximated by a plane. Its tilt in each coordinate direction comes from the two partial derivatives.

For a small move (Δx,Δy), the estimate ΔT≈TₓΔx+TᵧΔy adds the contribution from each direction.

Units verify the calculation: degrees per kilometre times kilometres gives degrees, so the two terms can be added to the starting temperature.

A mixed partial such as T_xy measures how the eastward slope itself changes as we travel north. That detects interactions not visible in one straight slice.

Weather software repeats this local calculation on a grid, but the derivatives usually come from fitted or simulated fields because raw station readings are sparse.

The approximation supports short-range interpolation and sensor planning; it does not replace the full atmosphere model for a large journey or long forecast.

In symbolsT(a+Δx,b+Δy)≈T(a,b)+TₓΔx+TᵧΔy

Worked example

Near a station, T(x,y)=20+2x−y+0.1xy. Estimate T(1.04,1.98) by linearising at (1,2), with distance in km.

  1. Evaluate the starting temperature: T(1,2)=20+2−2+0.2=20.2°C.
  2. Differentiate with respect to x while holding y fixed: Tₓ=2+0.1y.
  3. At (1,2), Tₓ=2.2°C per eastward kilometre.
  4. Differentiate with respect to y: Tᵧ=−1+0.1x, so Tᵧ(1,2)=−0.9°C per northward kilometre.
  5. The move is Δx=0.04 km and Δy=−0.02 km.
  6. Estimate ΔT≈2.2(0.04)+(−0.9)(−0.02)=0.088+0.018=0.106°C.
  7. Add the change to the starting value: T≈20.2+0.106=20.306°C.
  8. The exact formula gives 20.30592°C, so the small difference is the ignored product of the two small moves.

Answer: Approximately 20.306°C.

Check your picture

For f(x,y)=x³+y, what is ∂f/∂x?

Reveal answer

3x².

This lesson versus the whole chapter

Your topic-specific practical example is above.

The final lesson collects five longer chapter-wide workflows for machine learning, LLMs, trading, physics, and everyday decisions.

Formula shelf

Symbols with meaning

Partial derivativefₓᵢ=∂f/∂xᵢ

Change one input while holding the others fixed.

Gradient∇f=[fₓ₁,…,fₓₙ]ᵀ

Direction and size of steepest local rise.

Directional derivativeDᵤf=∇f·u

Slope in unit direction u.

JacobianJᵢⱼ=∂Fᵢ/∂xⱼ

Local linear map from input changes to output changes.

Change of variables∫ᴿf(x)dx=∫ᵁf(T(u))|det JT|du

Corrects area or volume when coordinates stretch.

Vector-field work∫ᶜF·dr=∫F(r(t))·r′(t)dt

Accumulates the component of a field along a path.

Divergence theorem∯∂ⱽF·n dS=∭ⱽ∇·F dV

Equates outward boundary flux with sources inside a volume.

HessianHᵢⱼ=∂²f/∂xᵢ∂xⱼ

Matrix of local curvature.

Multivariable Taylorf(x+Δ)≈f(x)+∇fᵀΔ+½ΔᵀHΔ

Local quadratic approximation.

Linear-layer backprop∇ₓL=Wᵀg; ∇W L=gxᵀ

Pass sensitivity through z=Wx+b.

Tensor contractionY[b,t,o]=sum over d of X[b,t,d]W[d,o]

Contracts feature axis d while retaining batch, token, and output axes.

Log-sum-expLSE(z)=m+logΣᵢeᶻᶦ⁻ᵐ

Computes a smooth maximum and softmax normalizer without overflow.

Softmax JacobianJ=diag(p)−ppᵀ

Captures how all normalized probabilities respond together.

Log-determinant gradientW log det W=W⁻ᵀ

Differentiates volume change for an invertible positive-determinant matrix.

Hessian-vector productHv=d[∇f(x+εv)]/dε|₀

Measures curvature along v without forming the full Hessian.

Before moving on

You are ready when you can…

  • Compute and interpret partial derivatives and tangent planes.
  • Use gradients and directional derivatives geometrically.
  • Build Jacobians with correct shapes and compose them.
  • Set up double and triple integrals, apply Jacobian factors, and interpret line integrals, divergence, curl, Green, Stokes, and divergence theorems with their assumptions.
  • Use Hessians to describe curvature and stationary points.
  • Track batch, sequence, and feature axes; apply broadcasting rules; and shape-check tensor contractions and einsum expressions.
  • Differentiate vector and matrix expressions and trace a backward pass.
  • Derive stable log-sum-exp, softmax Jacobians, and the fused softmax–cross-entropy gradient.
  • Use trace differentials, log-determinant rules, JVPs, VJPs, and Hessian-vector products with correct shapes.