Skip to the lesson
FixTheRobot Explore Robotics / Linear Algebra / M8 Jacobians and Robot Kinematics / M8-T3

Linear Algebra · Theory · M8

M8-T3 — Partial Derivatives

A partial derivative asks: if I nudge one input and hold the others fixed, how much does the output change? Collect the answers and you have a linear model of a nonlinear function.

  • Lesson 3 of 10
  • Module 8: Jacobians and Robot Kinematics
  • Jacobians and kinematics
  • About 9 minutes to read

The Jacobian is just a table of partial derivatives. Before building it, we need the tools to compute them correctly, check them numerically and use them to approximate a nonlinear function by a linear one. These are exactly the steps behind every linearised sensor model, every inverse-kinematics solver and every Gauss-Newton iteration.

Learning objectives

After this lesson, you should be able to:

  • Compute partial derivatives of functions such as range, bearing and arm kinematics.
  • Assemble the gradient and use the first-order (tangent) approximation f(x + δ) ≈ f(x) + ∇f·δ.
  • Apply the chain rule for compositions of functions of several variables.
  • Check analytic derivatives with finite differences and choose a sensible step size.

Introduction and motivation

A LiDAR measures range r = √(x² + y²) to a landmark. A filter wants to know how the range changes if the robot moves 10 cm east. A solver wants to know how the hand moves if the shoulder joint turns 1°. Both are partial derivatives: the sensitivity of one output to one input with the others frozen. Getting them right (and verifying them numerically) is a daily task, because almost every estimator and controller in robotics is built on linearisation.

The intuition

For a function of one variable the derivative is the slope of the tangent line. For a function of several variables, you can still slice: hold all inputs but one fixed and look at the resulting one-variable function. Its slope is the partial derivative with respect to that input. Several slopes, one per input, define a tangent plane (or hyperplane) that fits the function near the point. Replacing the curved function by that flat model is linearisation.

Linearisation: the tangent planeA curve and its tangent line at a point. Near the point the curve and the line agree to first order; far away they differ by a quadratic error. For functions of several variables the tangent line becomes a tangent plane built from the partial derivatives. x₀, f(x₀) f(x₀ + δ) ≈ f(x₀) + f′(x₀) δf(x₀ + δ, y₀ + ε) ≈ f + (∂f/∂x) δ + (∂f/∂y) ε tangenttrue curve The error is of order δ²: tiny for small steps, large for big ones.
Near a point the function is well approximated by its tangent; the error grows with the square of the step.

Interactive figure. A two-link arm with two arrows at the hand: the green one is the partial derivative of hand position with respect to the shoulder angle, the gold one with respect to the elbow angle. The readout gives the matrix of both. This figure needs JavaScript to be interactive.

Geometric and physical interpretation

Geometric view. The gradient ∇f = (∂f/∂x, ∂f/∂y) points in the direction of steepest increase of f, and its length is the slope in that direction. For a vector-valued function each component has its own gradient. Physical view. For the arm, ∂p/∂q₁ is the velocity of the hand per unit angular velocity of joint 1 with joint 2 locked: it is perpendicular to the line from joint 1 to the hand, with length equal to that distance. This is the familiar “velocity = ω × r”.

The mathematics

f(x, y)
a scalar function of two variables (the idea carries to n variables).
∂f/∂x
the partial derivative: differentiate with respect to x, treating y as a constant.
∇f
the gradient, the vector of partial derivatives.
δ
a small change in the inputs.

Definition

∂f/∂x (x, y) = lim_{h→0} [ f(x + h, y) − f(x, y) ] / h

What it means. Nudge only x by h, measure the change in f, divide by h and shrink h. All other inputs stay at their current values.

First-order approximation and the gradient

f(x + δ, y + ε) ≈ f(x, y) + (∂f/∂x) δ + (∂f/∂y) ε = f + ∇f · (δ, ε)

What it means. Near the point, the change in f is a weighted sum of the input changes with the partial derivatives as weights. The error is of second order in the step size.

The chain rule

d/dt f(x(t), y(t)) = (∂f/∂x) ẋ + (∂f/∂y) ẏ        (z = g(f(x)):  ∂z/∂x = (∂g/∂f)(∂f/∂x))

What it means. Derivatives of compositions multiply (and, for vector functions, become matrix products, which is why the Jacobian of a chain is a product of Jacobians).

Partial derivative: slope along one input with the others frozen. Gradient = vector of partials. f(x + δ) ≈ f(x) + ∇f·δ, with error of order δ².

Step-by-step derivation: gradients of range and the arm, and finite differences

  1. Range. r = (x² + y²)^(1/2). Using the chain rule: ∂r/∂x = ½(x² + y²)^(−1/2)·2x = x/r and ∂r/∂y = y/r. So ∇r = (x/r, y/r): the unit vector pointing away from the origin. Moving a distance d directly away from the landmark changes the range by exactly d; moving perpendicular changes it (to first order) by zero.
  2. Bearing. β = atan2(y, x) gives ∂β/∂x = −y/r² and ∂β/∂y = x/r²: the sensitivity falls as 1/r, so far landmarks give small angular changes per metre.
  3. Arm. Differentiate x = l₁ cos q₁ + l₂ cos(q₁ + q₂): ∂x/∂q₁ = −l₁ sin q₁ − l₂ sin(q₁ + q₂), ∂x/∂q₂ = −l₂ sin(q₁ + q₂). Likewise y = l₁ sin q₁ + l₂ sin(q₁ + q₂) gives ∂y/∂q₁ = l₁ cos q₁ + l₂ cos(q₁ + q₂), ∂y/∂q₂ = l₂ cos(q₁ + q₂). The inner angle q₁ + q₂ contributes through the chain rule, which is why q₁ appears in both terms.
  4. Finite differences. Replace the limit by a small step. Forward difference: (f(x + h) − f(x))/h has truncation error about (h/2)f″. Central difference: (f(x + h) − f(x − h))/(2h) has error about (h²/6)f‴, much smaller for the same h, at the price of two evaluations.
  5. Choosing h. A step that is too large has big truncation error; one that is too small loses digits to rounding (subtracting nearly equal numbers). For central differences in double precision a good h is about ∛ε·(1 + |x|) ≈ 10⁻⁵ · (1 + |x|) (with ε = 2.2 × 10⁻¹⁶).
  6. Linearisation error. By Taylor's theorem, f(x + δ) = f(x) + f′(x)δ + ½f″(x)δ² + …, so the error of the tangent approximation is about ½|f″|δ²: halving the step quarters the error.

Gradient checking is a debugging habit. Whenever you write an analytic Jacobian for a filter or optimiser, compare it with central differences at a few random points. Mismatch beyond about 1e-6 relative means an algebra, sign or unit error. This single test catches most bugs in EKF and bundle-adjustment code.

The multivariate chain rule. If y = g(u) and u = f(x), then ∂yᵢ/∂xⱼ = Σₖ (∂yᵢ/∂uₖ)(∂uₖ/∂xⱼ): sum over every path from xⱼ to yᵢ. In matrix form, the Jacobians multiply: J_{g∘f} = J_g J_f. This is how the sensor model Jacobian is built from the Jacobian of the frame transformation and the Jacobian of the polar conversion.

A worked example: gradients, linearisation and a finite-difference check

  • A simple function. f(x, y) = x²y: ∂f/∂x = 2xy, ∂f/∂y = x². At (1, 2) the gradient is (4, 1).
  • Finite-difference check. A central difference in x at (1, 2) with h = 10⁻⁶: (f(1 + h, 2) − f(1 − h, 2))/(2h) = 4.000000 ✓. A forward difference with h = 0.1 on x² at x = 1 gives (1.21 − 1)/0.1 = 2.1 versus the exact 2: an error of 0.1, equal to h.
  • Range gradient. At the landmark (3, 4), r = 5 and ∇r = (3/5, 4/5) = (0.6, 0.8).
  • Linearisation. Move the landmark by (0.1, 0): prediction Δr ≈ 0.6·0.1 = 0.06; exact √(3.1² + 4²) − 5 = 0.06063. The error 0.0006 is of order δ² as expected.
  • Bearing gradient. ∂β/∂x = −4/25 = −0.16, ∂β/∂y = 3/25 = 0.12 rad per metre.
  • Arm partials. For q = (0°, 90°) with l₁ = 1.1, l₂ = 0.8: ∂x/∂q₁ = −0 − 0.8 = −0.8, ∂y/∂q₁ = 1.1 + 0 = 1.1, ∂x/∂q₂ = −0.8, ∂y/∂q₂ = 0. So rotating the shoulder 1° (0.01745 rad) moves the hand by about (−0.0140, 0.0192) m.

Robotics application

SLAM and EKF. The measurement Jacobian of a range-bearing sensor is exactly the matrix of the partial derivatives above, evaluated at the current estimate; see EKF-SLAM and nonlinear least squares.

UAV state estimation. The extended Kalman filter linearises the motion and measurement models with partial derivatives with respect to the state; see the extended Kalman filter.

Manipulators. The columns of the arm Jacobian are the partials of hand position with respect to each joint (next lesson).

LiDAR registration. Gauss-Newton ICP linearises the point-to-plane residual with respect to the pose parameters: the same first-order approximation; see ICP fundamentals.

Engineering implications and limitations

Practical rules

  • Verify analytic derivatives numerically. A central-difference check at random states, with relative tolerance about 1e-6, finds most Jacobian bugs.
  • Use central differences and a scaled step. h ≈ 1e-5 (1 + |x|) in double precision; forward differences with h ≈ 1e-8 are the fallback when evaluations are expensive.
  • Keep units straight. Partial derivatives carry units: metres per radian for the arm, radians per metre for bearing. Mixing them in one matrix needs scaling before norms or condition numbers are meaningful.
  • Watch singular points. Range has no derivative at r = 0, atan2 jumps at ±π; guard against dividing by r when r is tiny.
  • Linearise only for small steps. The tangent approximation error grows like δ²; re-linearise at every iteration or time step.
  • Prefer analytic or automatic differentiation in production. Finite differences are for checking and quick prototypes; they are noisy and cost n extra evaluations.

Limits

The partial derivatives describe the function only near the point. Functions with kinks, such as |x| or contact models, have no derivative there, and strong curvature makes the linear model invalid for all but tiny steps.

Common misconceptions

“The partial derivative with respect to x is the full rate of change of f.”

It is the rate when only x changes. If other inputs change too, add their contributions (the chain rule).

“A smaller finite-difference step is always better.”

Too small loses precision to rounding. There is an optimal step, around the cube root of machine precision for central differences.

“The linear approximation is exact for small steps.”

It has error of order δ²; it is accurate for small steps, not exact.

“The range sensitivity is the same everywhere.”

Range changes at unit rate directly away from the landmark and not at all (to first order) perpendicular to it; bearing sensitivity falls like 1/r.

Engineering takeaways

  1. A partial derivative is the slope of f along one input with the others held fixed; the gradient collects them.
  2. f(x + δ) ≈ f(x) + ∇f·δ, with error of order δ²: that is linearisation.
  3. The chain rule multiplies derivatives; for vector functions it multiplies Jacobians.
  4. Range gradient is (x/r, y/r); arm partials come from differentiating the link vectors with the chain rule.
  5. Check analytic derivatives with central differences using a scaled step of about 1e-5.

References and further reading

Primary papers and authoritative documentation.

Knowledge check

Three conceptual questions. Write an answer, then reveal the explanation. Your answers stay in your browser.

Question 1

Compute the gradient of f(x, y) = x² + 3xy at (2, 1) and the predicted change for the step (0.1, −0.1).

Explanation

∂f/∂x = 2x + 3y = 7, ∂f/∂y = 3x = 6. Prediction Δf ≈ 7·0.1 + 6·(−0.1) = 0.1. Exact: f(2.1, 0.9) − f(2, 1) = (4.41 + 5.67) − (4 + 6) = 0.08, so the linearisation error is 0.02.

Question 2

A landmark is at (6, 8) from the robot. By how much does the range change to first order if the robot moves 0.2 m in +x? What if it moves 0.2 m perpendicular to the line of sight?

Explanation

r = 10, ∇r = (0.6, 0.8): Δr ≈ 0.6·0.2 = 0.12 m for +x. Perpendicular to the line of sight (direction (−0.8, 0.6)): Δr ≈ ∇r·0.2(−0.8, 0.6) = 0.2(−0.48 + 0.48) = 0, to first order.

Question 3

Your analytic Jacobian entry differs from a central-difference estimate by a factor of about 57.3. What is the likely bug?

Explanation

A degrees-versus-radians mix-up (180/π = 57.3): the derivative with respect to an angle in degrees is π/180 times the derivative with respect to radians. Check that the function and its derivative use the same angle unit.

What’s next

Stacking the partial derivatives of every output with respect to every input gives the Jacobian matrix: the best local linear approximation of a vector function, and the star of the rest of this module.

Next lesson

M8-T4 — Jacobian Matrices

Assemble the Jacobian of a vector function and read it as the best local linear approximation.

Nothing below is required to finish this lesson.