Skip to content
Tutorials Center
My learning

Topics

Lesson 3 of 44 · Getting Started

The Math Toolkit: Partial Derivatives and the Chain Rule

Learn the three calculus tools used all course long: partial derivatives, the chain rule, and total time derivatives of functions like L(q, q̇, t), with worked examples.

Almost every equation in this course is built from three operations: partial derivatives, the chain rule, and integration by parts. None is hard, but they must be second nature, because Lagrangians depend on several quantities at once (positions, velocities, time) and we must differentiate with respect to one while the others stay put. This lesson introduces each operation with the mechanics notation you will see later.

Elliptical contour lines of f(x, y) with arrows showing partial derivatives and the gradient at one point.
A contour map: the partials are slopes along the coordinate directions; the gradient points where f rises fastest.

What you will learn

  • What a partial derivative measures and how to compute one.
  • The multivariable chain rule and why d/dt differs from ∂/∂t.
  • Why we treat q and q̇ as independent inside L.
  • How integration by parts moves a derivative from one factor to another.

Key terms

A partial derivative ∂f/∂x differentiates in one variable with all others fixed. The gradient ∇f collects all partials. The total derivative df/dt follows a function along a motion. Integration by parts is ∫ u v′ dt = u v − ∫ u′ v dt.

Partial derivatives

For f(x, y) = x² + 2y², the partial derivatives are

Text
∂f/∂x = 2x      (treat y as a constant)
∂f/∂y = 4y      (treat x as a constant)

Geometrically, slice the surface z = f(x, y) with a vertical plane parallel to the x axis: ∂f/∂x is the slope of the cut. The contour picture above shows the same thing from the top. The vector of both partials is the gradient, ∇f = (∂f/∂x, ∂f/∂y) = (2x, 4y). It is perpendicular to the contour through the point and points uphill.

Two practical rules:

  • Constants and other variables simply ride along: ∂/∂x (3y²x) = 3y².
  • Mixed partials commute for smooth functions: ∂²f/∂x∂y = ∂²f/∂y∂x.

The chain rule

Suppose x and y are functions of time, x(t), y(t), so f changes as the particle moves. Then

Text
df/dt = (∂f/∂x) ẋ + (∂f/∂y) ẏ

Each term says: change in f per unit change in x, times how fast x changes. If f also has explicit time dependence, f(x, y, t), add ∂f/∂t:

Text
df/dt = ∂f/∂t + Σ (∂f/∂qᵢ) q̇ᵢ

Worked example. For f = x² + 2y² and the circle x = cos t, y = sin t:

Text
df/dt = 2x · ẋ + 4y · ẏ = 2cos t (−sin t) + 4 sin t cos t = 2 sin t cos t = sin 2t

Check by substituting first: f = cos² t + 2 sin² t = 1 + sin² t, so df/dt = 2 sin t cos t. ✓.

Why q and q̇ are independent inside L

A Lagrangian such as L = ½ m q̇² − ½ k q² is a function of two symbols, q and q̇. At a fixed instant you can choose a position and a velocity freely (throw the particle from the same point at any speed), so mathematically they are independent variables. We therefore take

Text
∂L/∂q̇ = m q̇        and        ∂L/∂q = −k q

and only afterwards recall that q and q̇ depend on time. Then d/dt (∂L/∂q̇) = m q̈ follows from the ordinary chain rule: m q̇ depends on t through q̇(t). This "partial first, total derivative second" order appears in every Euler-Lagrange equation.

Do not confuse ∂L/∂t with dL/dt. ∂L/∂t is nonzero only if L contains t explicitly (a driven system). dL/dt is nonzero whenever L changes along the motion, which is nearly always.

Integration by parts

From the product rule, d(u v)/dt = u′ v + u v′, integrate both sides:

Text
∫ₐᵇ u v′ dt = [u v]ₐᵇ − ∫ₐᵇ u′ v dt

In chapter 3 we will use it to move a derivative off a variation η′ and onto ∂L/∂y′; the boundary term [u v] vanishes because η = 0 at the ends.

Worked examples with numbers

Partial derivatives. Let f(x, y) = x²y at the point (2, 3). Holding y = 3 fixed gives ∂f/∂x = 2xy = 12. Holding x = 2 fixed gives ∂f/∂y = x² = 4. The gradient is ∇f = (12, 4), pointing in the direction where f increases fastest, and its length √(144 + 16) ≈ 12.65 is that steepest rate of increase.

Chain rule. Now let the point move along x = t, y = t². Then f = t⁴, so df/dt = 4t³. The chain rule gives the same answer from the partials: df/dt = (∂f/∂x) ẋ + (∂f/∂y) ẏ = 2xy · 1 + x² · 2t = 2t³ + 2t³ = 4t³. At t = 2 both routes give 32. This is the machinery behind every "derivative along the motion" in the course.

Derivatives of a Lagrangian. Take L = ½ m q̇² − ½ k q² with m = 2 kg, k = 50 N/m. Then ∂L/∂q̇ = m q̇, which equals 6 kg·m/s at q̇ = 3 m/s, and ∂L/∂q = −k q, which equals −25 N at q = 0.5 m. Notice what we did: we differentiated with respect to q̇ while treating q as a constant, and vice versa. That is legitimate because, at a single instant, the position and velocity can be chosen independently (see the section above).

Integration by parts. Evaluate ∫₀^π t sin t dt. Choose u = t, v′ = sin t, so v = −cos t: the integral is [−t cos t]₀^π + ∫₀^π cos t dt = π + 0 = π. In chapter 3 the same move, with the variation δq playing the role of v and the boundary term vanishing because δq = 0 at the endpoints, turns ∂L/∂q̇ · δq̇ into −d/dt(∂L/∂q̇) δq.

Notation that trips people up

Physicists write ∂L/∂q̇ for the derivative with respect to the velocity variable, and d/dt for a full time derivative that also differentiates the q and q̇ hidden inside. In d/dt(∂L/∂q̇) = m q̈ the symbol q̈ appears only after the time derivative is taken. Get used to reading these as two different operations. The curly ∂ was introduced by Legendre (1786) and made standard by Carl Jacobi in the 1840s, precisely to tell partial derivatives apart from total ones.

Common misconceptions

"∂f/∂x is just df/dx." Only for a function of one variable. With several variables the partial holds the others fixed, which is a different question from how f changes along a motion.

"If q̇ depends on q, then ∂L/∂q must include it." Not inside L. Along an actual motion there is a relation, but the function L(q, q̇) treats the two as independent inputs.

Try it

First let Python do the symbolic work: partial derivatives, the chain rule check, and the harmonic oscillator Lagrangian derivatives.

Python Partials, chain rule and ∂L/∂q̇

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Now a picture: contours of f, a circular path and the gradient at several points. The gradient arrows always cross the contours at right angles.

Python Gradient arrows cross the contours at right angles

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Check your understanding

Quick check · 5 questions

of 5 answered You scored / 5 · perfect!

  1. 1. For f(x, y) = 3x²y, what is ∂f/∂y?

    Treat x as a constant: the derivative of 3x² y with respect to y is 3x².
  2. 2. A particle moves with x(t), y(t). The total rate of change of f(x, y) is:

    That is the chain rule. If f has no explicit t, there is no ∂f/∂t term.
  3. 3. For L = ½ m q̇² − ½ k q², what is d/dt (∂L/∂q̇)?

    ∂L/∂q̇ = m q̇; differentiating with respect to time gives m q̈.
  4. 4. Why is the boundary term in integration by parts often zero in variational problems?

    The varied paths all start and end at the same points, so η(a) = η(b) = 0.
  5. 5. Which statement about the gradient ∇f is true?

    The gradient is normal to level curves and points toward increasing f.

Summary

  • A partial derivative differentiates in one variable while freezing the others.
  • The chain rule gives df/dt = ∂f/∂t + Σ (∂f/∂qᵢ) q̇ᵢ; d/dt and ∂/∂t are different things.
  • Inside L(q, q̇, t) the symbols q and q̇ are independent; time dependence is added afterwards.
  • Integration by parts moves a derivative from one factor to the other and produces a boundary term.

Next: Generalized Coordinates and Degrees of Freedom