Skip to content

Chapter 10: Calculus 3

Multivariable calculus generalizes the single-variable ideas of derivative and integral to functions of several variables. The gradient replaces the derivative, multiple integrals replace single integrals, and the classical theorems of Green, Stokes, and Gauss reveal that integration over a region and integration over its boundary are deeply related. For computing, the payoff is direct: the gradient is the engine of optimization (gradient descent), the Jacobian is the engine of backpropagation, and multiple integrals compute joint probabilities.

Concepts from other sections (24)

This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.

This chapter has two parts. Its two build sections turn partial derivatives and Jacobians into code that later chapters depend on: a gradient checker that referees every backward rule you will ever write, and numeric oracles for the Jacobian-vector and vector-Jacobian products that forward and reverse mode compute. Its problem set then works the hand computations behind the rest of the subject: vectors and geometry, gradients, the chain rule, directional derivatives, Hessians, multiple integrals, and Lagrange multipliers. The survey below the section list covers the wider territory of a Calculus 3 course, including vector-valued functions and vector calculus, with a worked example for each topic.

Learning objectives

  • Compute partial derivatives, gradients, and directional derivatives, and explain why −∇f-\nabla f is the direction of steepest descent.
  • Build and use a numerical gradient check with a mixed absolute and relative tolerance.
  • Form Jacobians, apply the multivariable chain rule as a matrix product, and compute JVPs and VJPs without forming the matrix.
  • Classify critical points with the Hessian, and solve constrained problems with Lagrange multipliers.
  • Evaluate double and triple integrals with a change of variables, and state Green’s, Stokes’, and the Divergence theorems.

You should be comfortable with one-variable derivatives and finite differences from Calculus 1, especially Derivatives and Finite Differences, whose central_diff the first section calls; with Taylor series from Calculus 2; and with matrices, row-major layout, and matrix products from Linear Algebra, especially Vectors, matrices, row-major layout, and matmul.

  1. Partial derivatives, gradients, and gradcheck: builds the gradient of a scalar function of several arrays from one central difference per element, and a gradcheck that rejects real backward-pass bugs and points at the element furthest past its tolerance.
  2. Jacobians, the multivariable chain rule, and numeric JVP/VJP: defines the Jacobian and the chain rule as a matrix product, and builds numeric oracles for JvJv and u⊤Ju^\top J that the autodiff chapter checks against.
  3. Calculus 3 problem set: 58 problems with worked answers on vectors, gradients, the chain rule, directional derivatives, Hessians, multiple integrals, and Lagrange multipliers. It is the book’s treatment of the Hessian, multiple integrals, and Lagrange multipliers.

The sections above focus on the parts of multivariable calculus that code depends on. The rest of this opening surveys the whole subject, following Calculus Volume 3 from OpenStax, so you can see where those parts sit. Each topic gives the key definitions and theorems, a worked example, and the textbook exercises to practice on.

Textbook chapter 2, sections 2.1 to 2.5. The dot product is u⋅v=u1v1+u2v2+u3v3=∥u∥∥v∥cos⁡θu \cdot v = u_1 v_1 + u_2 v_2 + u_3 v_3 = \lVert u \rVert \lVert v \rVert \cos\theta. It measures how much two vectors point in the same direction; zero means perpendicular. The cross product is

u×v=(u2v3−u3v2,  u3v1−u1v3,  u1v2−u2v1),u \times v = (u_2 v_3 - u_3 v_2,\; u_3 v_1 - u_1 v_3,\; u_1 v_2 - u_2 v_1),

perpendicular to both uu and vv, with magnitude ∥u×v∥=∥u∥∥v∥sin⁡θ\lVert u \times v \rVert = \lVert u \rVert \lVert v \rVert \sin\theta, the area of the parallelogram they span. So the cross product encodes both a direction (normal to the plane of uu and vv) and a magnitude (area). The triple scalar product u⋅(v×w)=det⁡([u;v;w])u \cdot (v \times w) = \det([u; v; w]) is the signed volume of the parallelepiped: determinants measure volume, and the triple product is exactly a 3×33 \times 3 determinant.

A line in space is r(t)=r0+tdr(t) = r_0 + t d, a point plus a direction. A plane is n⋅(r−r0)=0n \cdot (r - r_0) = 0, or ax+by+cz=dax + by + cz = d where (a,b,c)(a, b, c) is the normal vector.

For example, find the plane through (1,2,3)(1,2,3), (2,0,1)(2,0,1), and (0,1,2)(0,1,2). Two vectors in the plane are v=(1,−2,−2)v = (1,-2,-2) and w=(−1,−1,−1)w = (-1,-1,-1). The normal is

v×w=((−2)(−1)−(−2)(−1),  (−2)(−1)−1⋅(−1),  1⋅(−1)−(−2)(−1))=(0,3,−3),v \times w = \bigl((-2)(-1)-(-2)(-1),\; (-2)(-1)-1\cdot(-1),\; 1\cdot(-1)-(-2)(-1)\bigr) = (0, 3, -3),

which simplifies to (0,1,−1)(0,1,-1). The plane is (y−2)−(z−3)=0(y-2) - (z-3) = 0, or y−z+1=0y - z + 1 = 0.

Practice: OpenStax 2.3 exercises 123 to 135, 2.4 exercises 161 to 175, and 2.5 exercises 215 to 228; for a challenge, 2.5 exercises 237 to 242.

Textbook chapter 3, sections 3.1 to 3.4. A vector-valued function r(t)=⟨x(t),y(t),z(t)⟩r(t) = \langle x(t), y(t), z(t) \rangle describes a curve in space. Its derivative r′(t)=⟨x′(t),y′(t),z′(t)⟩r'(t) = \langle x'(t), y'(t), z'(t) \rangle is the tangent vector, the arc length is L=∫ab∥r′(t)∥ dtL = \int_a^b \lVert r'(t) \rVert\,dt, and the unit tangent is T(t)=r′(t)/∥r′(t)∥T(t) = r'(t) / \lVert r'(t) \rVert. Every smooth curve can be reparameterized by arc length ss so that ∥r′(s)∥=1\lVert r'(s) \rVert = 1 everywhere: traveling at unit speed, the parameter directly measures distance along the curve.

Curvature measures how sharply a curve bends:

κ=∥T′(t)∥∥r′(t)∥=∥r′(t)×r′′(t)∥∥r′(t)∥3.\kappa = \frac{\lVert T'(t) \rVert}{\lVert r'(t) \rVert} = \frac{\lVert r'(t) \times r''(t) \rVert}{\lVert r'(t) \rVert^3}.

A straight line has κ=0\kappa = 0; a circle of radius RR has κ=1/R\kappa = 1/R. For the helix r(t)=⟨cos⁡t,sin⁡t,t⟩r(t) = \langle \cos t, \sin t, t \rangle: r′(t)=⟨−sin⁡t,cos⁡t,1⟩r'(t) = \langle -\sin t, \cos t, 1 \rangle with ∥r′∥=2\lVert r' \rVert = \sqrt2, r′′(t)=⟨−cos⁡t,−sin⁡t,0⟩r''(t) = \langle -\cos t, -\sin t, 0 \rangle, and r′×r′′=⟨sin⁡t,−cos⁡t,1⟩r' \times r'' = \langle \sin t, -\cos t, 1 \rangle with ∥r′×r′′∥=2\lVert r' \times r'' \rVert = \sqrt2. So κ=2/(2)3=1/2\kappa = \sqrt2 / (\sqrt2)^3 = 1/2: the helix has constant curvature 1/21/2.

Practice: OpenStax 3.2 exercises 60 to 72, 3.3 exercises 100 to 112, and 3.4 exercises 130 to 140; for a challenge, 3.4 exercises 145 to 150.

Textbook chapter 4, sections 4.1 to 4.8. The partial derivative fx(x,y)=lim⁡h→0[f(x+h,y)−f(x,y)]/hf_x(x,y) = \lim_{h \to 0} [f(x+h,y) - f(x,y)]/h differentiates with respect to xx holding yy constant. The gradient ∇f=(fx,fy,fz)\nabla f = (f_x, f_y, f_z) points in the direction of steepest ascent, and the directional derivative Duf=∇f⋅uD_u f = \nabla f \cdot u is the rate of change in direction uu. The tangent plane at (x0,y0)(x_0, y_0) is z−z0=fx(x0,y0)(x−x0)+fy(x0,y0)(y−y0)z - z_0 = f_x(x_0,y_0)(x - x_0) + f_y(x_0,y_0)(y - y_0). A critical point is where ∇f=0\nabla f = 0 or ∇f\nabla f is undefined, and the Hessian H=(fxxfxyfyxfyy)H = \begin{pmatrix} f_{xx} & f_{xy} \\ f_{yx} & f_{yy} \end{pmatrix} encodes second-order behavior.

Four results organize the topic. The multivariable chain rule: if z=f(x,y)z = f(x,y) with x=x(t)x = x(t), y=y(t)y = y(t), then dz/dt=fx dx/dt+fy dy/dtdz/dt = f_x\,dx/dt + f_y\,dy/dt; each variable contributes its own rate of change, weighted by how the function responds to it. Clairaut’s theorem: if fxyf_{xy} and fyxf_{yx} are continuous, they are equal, so the order of mixed partials does not matter under mild smoothness. The second derivative test: at a critical point (a,b)(a,b), let D=fxxfyy−fxy2D = f_{xx} f_{yy} - f_{xy}^2; if D>0D > 0 and fxx>0f_{xx} > 0 it is a local minimum, if D>0D > 0 and fxx<0f_{xx} < 0 a local maximum, and if D<0D < 0 a saddle. DD is the determinant of the Hessian, and it checks whether the surface curves the same way in all directions. Lagrange multipliers: to optimize ff subject to g=cg = c, solve ∇f=λ∇g\nabla f = \lambda \nabla g and g=cg = c. At a constrained extremum the gradient of ff must be parallel to the gradient of gg; otherwise you could improve ff by moving along the constraint.

Two worked examples. First, minimize f(x,y)=x2+y2f(x,y) = x^2 + y^2 subject to x+y=4x + y = 4. Lagrange gives (2x,2y)=λ(1,1)(2x, 2y) = \lambda(1, 1), so 2x=λ=2y2x = \lambda = 2y and x=yx = y. The constraint gives x=y=2x = y = 2, and the minimum is f(2,2)=8f(2,2) = 8.

Second, classify the critical points of f(x,y)=x3−3xy+y3f(x,y) = x^3 - 3xy + y^3. Setting fx=3x2−3y=0f_x = 3x^2 - 3y = 0 and fy=−3x+3y2=0f_y = -3x + 3y^2 = 0, the first gives y=x2y = x^2; substituting, −3x+3x4=0-3x + 3x^4 = 0, so x(x3−1)=0x(x^3 - 1) = 0, giving (0,0)(0,0) and (1,1)(1,1). At (1,1)(1,1), fxx=6f_{xx} = 6, fyy=6f_{yy} = 6, fxy=−3f_{xy} = -3, so D=36−9=27>0D = 36 - 9 = 27 > 0 with fxx>0f_{xx} > 0: a local minimum. At (0,0)(0,0), D=0−9=−9<0D = 0 - 9 = -9 < 0: a saddle.

Practice: OpenStax 4.3 exercises 115 to 128, 4.5 exercises 200 to 215, 4.6 exercises 240 to 252, and 4.8 exercises 340 to 355; for a challenge, 4.8 exercises 360 to 368.

Textbook chapter 5, sections 5.1 to 5.7. A double integral ∬Rf(x,y) dA\iint_R f(x,y)\,dA is computed as iterated integrals over xx and yy, and a triple integral ∭Ef(x,y,z) dV\iiint_E f(x,y,z)\,dV likewise. Fubini’s theorem says that if ff is continuous on a rectangle R=[a,b]×[c,d]R = [a,b] \times [c,d], the double integral equals either iterated integral: you can slice horizontally or vertically and get the same answer.

Other coordinate systems simplify circular and spherical regions. Polar: x=rcos⁡θx = r\cos\theta, y=rsin⁡θy = r\sin\theta, dA=r dr dθdA = r\,dr\,d\theta. Cylindrical: (r,θ,z)(r, \theta, z) with dV=r dr dθ dzdV = r\,dr\,d\theta\,dz. Spherical: x=ρsin⁡ϕcos⁡θx = \rho\sin\phi\cos\theta, y=ρsin⁡ϕsin⁡θy = \rho\sin\phi\sin\theta, z=ρcos⁡ϕz = \rho\cos\phi, dV=ρ2sin⁡ϕ dρ dϕ dθdV = \rho^2 \sin\phi\,d\rho\,d\phi\,d\theta. All are instances of the change of variables formula. For a transformation (x,y)=T(u,v)(x,y) = T(u,v) with Jacobian determinant J=det⁡(∂x/∂u∂x/∂v∂y/∂u∂y/∂v)J = \det\begin{pmatrix} \partial x/\partial u & \partial x/\partial v \\ \partial y/\partial u & \partial y/\partial v \end{pmatrix}, dA=∣J∣ du dvdA = |J|\,du\,dv and

∬Rf(x,y) dA=∬Sf(T(u,v)) ∣J∣ du dv.\iint_R f(x,y)\,dA = \iint_S f(T(u,v))\,|J|\,du\,dv.

The Jacobian determinant measures how much the transformation stretches or compresses area, just as ∣dx/du∣|dx/du| does in single-variable substitution.

For example, integrate x2+y2x^2 + y^2 over the disk x2+y2≤4x^2 + y^2 \le 4. In polar coordinates,

∫02π ⁣∫02r2⋅r dr dθ=∫02πdθ∫02r3 dr=2π[r44]02=2π⋅4=8π.\int_0^{2\pi}\!\int_0^2 r^2 \cdot r\,dr\,d\theta = \int_0^{2\pi} d\theta \int_0^2 r^3\,dr = 2\pi \left[\frac{r^4}{4}\right]_0^2 = 2\pi \cdot 4 = 8\pi.

Practice: OpenStax 5.1 exercises 1 to 14, 5.3 exercises 130 to 145, 5.5 exercises 240 to 255, and 5.7 exercises 340 to 352; for a challenge, 5.7 exercises 358 to 365.

Textbook chapter 6, sections 6.1 to 6.8. A vector field is F(x,y,z)=⟨P,Q,R⟩F(x,y,z) = \langle P, Q, R \rangle. The line integral of a scalar is ∫Cf ds=∫abf(r(t)) ∥r′(t)∥ dt\int_C f\,ds = \int_a^b f(r(t))\,\lVert r'(t) \rVert\,dt, and the line integral of a vector field, the work done by FF along CC, is ∫CF⋅dr=∫abF(r(t))⋅r′(t) dt\int_C F \cdot dr = \int_a^b F(r(t)) \cdot r'(t)\,dt. A field is conservative if F=∇fF = \nabla f for some scalar potential ff. Curl, ∇×F=(Ry−Qz,  Pz−Rx,  Qx−Py)\nabla \times F = (R_y - Q_z,\; P_z - R_x,\; Q_x - P_y), measures local rotation; divergence, ∇⋅F=Px+Qy+Rz\nabla \cdot F = P_x + Q_y + R_z, measures local expansion. A surface integral is ∬SF⋅dS=∬DF⋅(ru×rv) dA\iint_S F \cdot dS = \iint_D F \cdot (r_u \times r_v)\,dA.

Four theorems relate integrals over a region to integrals over its boundary:

  • Fundamental theorem for line integrals: if F=∇fF = \nabla f, then ∫CF⋅dr=f(B)−f(A)\int_C F \cdot dr = f(B) - f(A). For gradient fields, work depends only on the endpoints, not the path, just like the fundamental theorem of calculus.
  • Green’s theorem: ∮C(P dx+Q dy)=∬D(Qx−Py) dA\oint_C (P\,dx + Q\,dy) = \iint_D (Q_x - P_y)\,dA. The circulation around a closed curve equals the total curl inside.
  • Stokes’ theorem: ∮CF⋅dr=∬S(∇×F)⋅dS\oint_C F \cdot dr = \iint_S (\nabla \times F) \cdot dS. It generalizes Green’s theorem to 3D: the circulation of FF around a closed curve equals the flux of the curl through any surface bounded by that curve.
  • Divergence theorem: ∬SF⋅dS=∭E(∇⋅F) dV\iint_S F \cdot dS = \iiint_E (\nabla \cdot F)\,dV. The total outward flux through a closed surface equals the total divergence inside: what flows out must be produced within.

For example, use Green’s theorem to evaluate ∮C(y2 dx+x2 dy)\oint_C (y^2\,dx + x^2\,dy) around the unit circle, counterclockwise. With P=y2P = y^2 and Q=x2Q = x^2, Qx−Py=2x−2yQ_x - P_y = 2x - 2y, so the integral is ∬D(2x−2y) dA\iint_D (2x - 2y)\,dA. In polar coordinates this is ∫02π ⁣∫01(2rcos⁡θ−2rsin⁡θ) r dr dθ\int_0^{2\pi}\!\int_0^1 (2r\cos\theta - 2r\sin\theta)\,r\,dr\,d\theta, and since cos⁡θ\cos\theta and sin⁡θ\sin\theta each integrate to 0 over [0,2π][0, 2\pi], the result is 0.

Practice: OpenStax 6.2 exercises 55 to 70, 6.3 exercises 115 to 130, 6.4 exercises 155 to 168, 6.7 exercises 285 to 298, and 6.8 exercises 325 to 338; for a challenge, 6.8 exercises 345 to 352.

Most problems in the subject reduce to recognizing which tool applies. This table pairs each technique with when to reach for it:

TechniqueWhen to useKey formula or idea
Gradientfind the direction of steepest ascent∇f=(fx,fy,fz)\nabla f = (f_x, f_y, f_z)
Lagrange multipliersconstrained optimization∇f=λ∇g\nabla f = \lambda \nabla g
Second derivative testclassify critical points in 2Dcheck det⁡H\det H and fxxf_{xx}
Polar, cylindrical, spherical coordinatesintegrate over circular or spherical regionsinclude the Jacobian factor (rr, rr, ρ2sin⁡ϕ\rho^2 \sin\phi)
Green’s theoremconvert a line integral to a double integral (2D)circulation = integral of curl over the region
Stokes’ theoremconvert a line integral to a surface integral (3D)circulation = flux of curl
Divergence theoremconvert a surface integral to a volume integralflux = integral of divergence
Change of variablessimplify the integration domaindA=∣J∣ du dvdA = \lvert J \rvert\,du\,dv
  • Dot product: u⋅v=∑iuivi=∥u∥∥v∥cos⁡θu \cdot v = \sum_i u_i v_i = \lVert u \rVert \lVert v \rVert \cos\theta; it measures how much two vectors point the same way, and it is zero exactly when they are perpendicular.
  • Cross product: for vectors in 3D, u×vu \times v is perpendicular to both, with magnitude ∥u∥∥v∥sin⁡θ\lVert u \rVert \lVert v \rVert \sin\theta, the area of the parallelogram they span; it gives normals to planes.
  • Vector-valued function: a function r(t)=⟨x(t),y(t),z(t)⟩r(t) = \langle x(t), y(t), z(t) \rangle that traces a curve in space; its derivative r′(t)r'(t) is the tangent (velocity) vector, and ∫∥r′(t)∥ dt\int \lVert r'(t) \rVert\,dt is arc length.
  • Tangent plane: the plane z−z0=fx(x0,y0)(x−x0)+fy(x0,y0)(y−y0)z - z_0 = f_x(x_0, y_0)(x - x_0) + f_y(x_0, y_0)(y - y_0) that best approximates the surface z=f(x,y)z = f(x, y) near a point, the two-variable analogue of the tangent line.
  • Clairaut’s theorem: if the mixed partials fxyf_{xy} and fyxf_{yx} are continuous, they are equal, so the order of differentiation does not matter and the Hessian is symmetric.
  • Second derivative test (two variables): at a critical point, D=fxxfyy−fxy2D = f_{xx} f_{yy} - f_{xy}^2, the determinant of the Hessian, gives a local minimum if D>0D > 0 and fxx>0f_{xx} > 0, a local maximum if D>0D > 0 and fxx<0f_{xx} < 0, and a saddle if D<0D < 0.
  • Fubini’s theorem: for ff continuous on a rectangle, the double integral equals either iterated integral, so you can integrate over xx first or yy first and get the same answer.
  • Change of variables (multiple integrals): for a substitution (x,y)=T(u,v)(x, y) = T(u, v), dA=∣J∣ du dvdA = |J|\,du\,dv, where JJ is the Jacobian determinant of TT; it measures how TT stretches area, and it gives the rr in polar and the ρ2sin⁡ϕ\rho^2 \sin\phi in spherical coordinates.
  • Vector field: a function F(x,y,z)=⟨P,Q,R⟩F(x, y, z) = \langle P, Q, R \rangle that assigns a vector to every point, such as a velocity or force field; the gradient of a scalar function is one.
  • Line integral: an integral along a curve CC; for a vector field, ∫CF⋅dr=∫abF(r(t))⋅r′(t) dt\int_C F \cdot dr = \int_a^b F(r(t)) \cdot r'(t)\,dt is the work done by FF along CC.
  • Conservative vector field: a field that is the gradient of a scalar potential, F=∇fF = \nabla f; its line integrals depend only on the endpoints, and its integral around any closed curve is zero.
  • Fundamental theorem for line integrals: if F=∇fF = \nabla f, then ∫CF⋅dr=f(B)−f(A)\int_C F \cdot dr = f(B) - f(A) for any path from AA to BB, the analogue of the fundamental theorem of calculus for gradient fields.
  • Green’s theorem: ∮C(P dx+Q dy)=∬D(Qx−Py) dA\oint_C (P\,dx + Q\,dy) = \iint_D (Q_x - P_y)\,dA; the circulation around a closed plane curve equals the total curl inside the region it bounds.
  • Stokes’ theorem: ∮CF⋅dr=∬S(∇×F)⋅dS\oint_C F \cdot dr = \iint_S (\nabla \times F) \cdot dS; the circulation of FF around a closed curve equals the flux of its curl through any surface bounded by that curve, generalizing Green’s theorem to 3D.
  • Divergence theorem: ∬SF⋅dS=∭E(∇⋅F) dV\iint_S F \cdot dS = \iiint_E (\nabla \cdot F)\,dV; the outward flux through a closed surface equals the total divergence inside, so what flows out must be produced within.

The gradient and directional derivative drive gradient descent in Optimization. The Jacobian is the chain rule for vector functions, which is backpropagation, and Matrix calculus and autodiff builds it three ways. Lagrange multipliers underlie constrained optimization such as SVMs and regularization, and the reading of softmax as a maximum-entropy distribution in Information theory. Multiple integrals compute joint probability distributions and expected values in Probability and statistics. The change of variables formula is the core of normalizing flows in generative models, and divergence and curl appear in physics simulation and fluid dynamics for games.