∇ Multivariable Calculus

Vectors, Fields, Surfaces & the Topology of Higher Dimensions
A complete reference: rigorous proofs, cryptographic applications, interactive explorations & GNU Octave laboratory — all in one self-contained document.

§01 Vectors & Vector Spaces

1.1 — Vectors in ℝⁿ

A vector v ∈ ℝⁿ is an ordered n-tuple v = (v₁, v₂, …, vₙ). In ℝ³: v = v₁i + v₂j + v₃k. Vectors have magnitude and direction — they are the atoms of multivariable calculus.

‖v‖ = √(v₁² + v₂² + ⋯ + vₙ²)     (Euclidean norm)

1.2 — Dot Product

a · b = Σᵢ aᵢbᵢ = ‖a‖ ‖b‖ cos θ
PROOF — Dot product equals ‖a‖‖b‖ cos θ
By the law of cosines: ‖a − b‖² = ‖a‖² + ‖b‖² − 2‖a‖‖b‖cos θ.
Expand the left side: ‖a − b‖² = (a−b)·(a−b) = a·a − 2a·b + b·b = ‖a‖² + ‖b‖² − 2a·b.
Equating: −2a·b = −2‖a‖‖b‖cos θ, so a·b = ‖a‖‖b‖cos θ.

1.3 — Cross Product (ℝ³)

a × b = (a₂b₃ − a₃b₂)i − (a₁b₃ − a₃b₁)j + (a₁b₂ − a₂b₁)k
‖a × b‖ = ‖a‖ ‖b‖ sin θ    (area of parallelogram)
PROOF — Cross product is orthogonal to both factors
Compute a · (a × b) = a₁(a₂b₃−a₃b₂) − a₂(a₁b₃−a₃b₁) + a₃(a₁b₂−a₂b₁).
= a₁a₂b₃ − a₁a₃b₂ − a₂a₁b₃ + a₂a₃b₁ + a₃a₁b₂ − a₃a₂b₁ = 0.
Every term cancels in pairs. Identically b · (a × b) = 0.

1.4 — Triple Products

Scalar triple product: a · (b × c) = det[a | b | c]    (signed volume of parallelepiped)
Vector triple product: a × (b × c) = b(a·c) − c(a·b)    (BAC-CAB rule)

1.5 — Parametric Curves & Arc Length

A curve r(t) = (x(t), y(t), z(t)) for t ∈ [a,b]. The arc length is:

L = ∫ₐᵇ ‖r′(t)‖ dt = ∫ₐᵇ √(x′² + y′² + z′²) dt
PROOF — Arc length formula from Riemann sums
Partition [a,b] into n subintervals. On each, the chord length ≈ ‖r(tᵢ₊₁) − r(tᵢ)‖ = ‖r′(tᵢ*)‖Δt by MVT.
Summing: L ≈ Σ ‖r′(tᵢ*)‖Δt → ∫ₐᵇ ‖r′(t)‖ dt as n → ∞.

1.6 — Curvature

κ = ‖r′ × r″‖ / ‖r′‖³     (curvature of a space curve)

The Frenet-Serret frame {T, N, B} with T = r′/‖r′‖, N = T′/‖T′‖, B = T × N satisfies:

T′ = κN,    N′ = −κT + τB,    B′ = −τN

where τ is the torsion measuring how the curve twists out of its osculating plane.

§02 Partial Derivatives

2.1 — Definition

For f : ℝⁿ → ℝ, the partial derivative with respect to xᵢ is:

∂f/∂xᵢ = limh→0 [f(x₁,…,xᵢ+h,…,xₙ) − f(x₁,…,xᵢ,…,xₙ)] / h

Hold all other variables constant and differentiate with respect to one — this is the fundamental operation of multivariable calculus.

2.2 — Clairaut's Theorem (Symmetry of Mixed Partials)

THEOREM & PROOF — If fxy and fyx are continuous, then fxy = fyx
Consider the second-order difference quotient: Δ(h) = f(a+h,b+h) − f(a+h,b) − f(a,b+h) + f(a,b).
Define g(x) = f(x,b+h) − f(x,b). Then Δ = g(a+h) − g(a) = h·g′(ξ) = h·[fx(ξ,b+h) − fx(ξ,b)].
Apply MVT again: = h²·fxy(ξ,η) for some (ξ,η) near (a,b).
Alternatively, define φ(y) = f(a+h,y) − f(a,y). Then Δ = h²·fyx(ξ′,η′).
Both expressions equal Δ/h², so fxy(ξ,η) = fyx(ξ′,η′). As h → 0, by continuity: fxy(a,b) = fyx(a,b).

2.3 — Higher-Order Partials

For f : ℝ² → ℝ, the second-order partials form the Hessian matrix:

H = [ fxx fxy ]    (symmetric by Clairaut if C²) [ fyx fyy ]

2.4 — Linearization & Differentiability

f is differentiable at a if there exists a linear map L : ℝⁿ → ℝ such that:

limh→0 |f(a+h) − f(a) − L(h)| / ‖h‖ = 0

The matrix of L is the Jacobian [∂fᵢ/∂xⱼ]. For f : ℝⁿ → ℝ, this reduces to the gradient row vector.

THEOREM — Continuous partials ⟹ differentiable
If all partial derivatives ∂f/∂xᵢ exist in a neighbourhood of a and are continuous at a, then f is differentiable at a.
Sketch: Write f(a+h) − f(a) = Σᵢ [f(…,aᵢ+hᵢ,…) − f(…,aᵢ,…)] (telescoping). Apply MVT to each term: = Σ hᵢ ∂f/∂xᵢ(cᵢ). By continuity, ∂f/∂xᵢ(cᵢ) → ∂f/∂xᵢ(a), giving the linear approximation with o(‖h‖) error.

2.5 — The Chain Rule (Multivariable)

THEOREM — Multivariable Chain Rule
If f : ℝⁿ → ℝᵐ is differentiable at a and g : ℝᵐ → ℝᵖ is differentiable at f(a), then g∘f is differentiable at a and:
D(g∘f)(a) = Dg(f(a)) · Df(a)    (Jacobian matrices multiply)
In component form: ∂(g∘f)ᵢ/∂xⱼ = Σₖ (∂gᵢ/∂yₖ)(∂fₖ/∂xⱼ).
For the scalar case with z = f(x,y), x = x(s,t), y = y(s,t):
∂z/∂s = (∂z/∂x)(∂x/∂s) + (∂z/∂y)(∂y/∂s)
Proof: By differentiability, g(f(a+h)) − g(f(a)) = Dg·[f(a+h)−f(a)] + o(‖f(a+h)−f(a)‖) = Dg·[Df·h + o(‖h‖)] + o(‖Df·h + o(‖h‖)‖) = Dg·Df·h + o(‖h‖).

§03 Gradient & Directional Derivatives

3.1 — The Gradient Vector

For f : ℝⁿ → ℝ, the gradient is the vector of partial derivatives:

∇f = (∂f/∂x₁, ∂f/∂x₂, …, ∂f/∂xₙ)

The gradient points in the direction of steepest ascent and is perpendicular to level sets.

3.2 — Directional Derivative

Duf(a) = limt→0 [f(a + tu) − f(a)] / t = ∇f(a) · u

where u is a unit vector. The rate of change of f in direction u.

PROOF — Gradient gives maximum directional derivative
Duf = ∇f · u = ‖∇f‖ ‖u‖ cos θ = ‖∇f‖ cos θ (since ‖u‖ = 1).
This is maximized when cos θ = 1, i.e., u = ∇f/‖∇f‖.
Maximum rate of change = ‖∇f‖, achieved in the gradient direction.

3.3 — Gradient is Normal to Level Surfaces

PROOF — ∇f ⊥ level set {f = c}
Let r(t) be any curve on the level surface f(r(t)) = c.
Differentiate: d/dt[f(r(t))] = ∇f · r′(t) = 0.
So ∇f is orthogonal to every tangent vector r′(t) at the point, hence ∇f is normal to the surface.

3.4 — Interactive: Gradient Field Explorer

↑ Move cursor over the scalar field f(x,y) = sin(x)·cos(y). Arrows show ∇f, brightness shows f-value.

3.5 — Tangent Planes

For a surface F(x,y,z) = 0, the tangent plane at point (a,b,c) is:

Fx(a,b,c)(x−a) + Fy(a,b,c)(y−b) + Fz(a,b,c)(z−c) = 0

For z = f(x,y), the tangent plane is z − f(a,b) = fx(a,b)(x−a) + fy(a,b)(y−b).

§04 Optimization & Lagrange Multipliers

4.1 — Critical Points

A critical point of f : ℝⁿ → ℝ is where ∇f = 0 (or ∇f undefined). These are candidates for local extrema.

4.2 — Second Derivative Test (ℝ²)

THEOREM — Second Derivative Test via Hessian
At a critical point (a,b) where ∇f = 0, let D = fxxfyy − (fxy)² (the Hessian determinant).
If D > 0 and fxx > 0: local minimum.
If D > 0 and fxx < 0: local maximum.
If D < 0: saddle point.
If D = 0: test is inconclusive.
Proof sketch: The Hessian H is a 2×2 symmetric matrix. D = det(H). When D > 0, both eigenvalues have the same sign (determined by fxx), so the quadratic form hTHh is definite. When D < 0, eigenvalues have opposite signs (indefinite = saddle).

4.3 — Lagrange Multipliers

THEOREM & PROOF — Lagrange Multipliers
To extremize f(x) subject to g(x) = 0 where g : ℝⁿ → ℝ:
At a constrained extremum, ∇f must be parallel to ∇g (otherwise, moving along the constraint surface could increase f). So ∃λ ∈ ℝ such that:
∇f = λ ∇g
Rigorous argument: At a constrained extremum p, the constraint set g = 0 is locally a smooth manifold (by implicit function theorem, since ∇g ≠ 0). The tangent space Tp = {v : ∇g · v = 0}. Since f has an extremum restricted to the constraint, Dvf = ∇f · v = 0 for all v ∈ Tp. So ∇f annihilates ker(∇g), meaning ∇f ∈ span(∇g), i.e., ∇f = λ∇g.

4.4 — Multiple Constraints

With constraints g₁(x) = 0, …, gₖ(x) = 0:

∇f = λ₁∇g₁ + λ₂∇g₂ + ⋯ + λₖ∇gₖ

This gives n + k equations in n + k unknowns (x₁,…,xₙ,λ₁,…,λₖ).

4.5 — Interactive: Gradient Descent on a Surface

0.10
↑ Click surface to place start point; gradient descent (−∇f) path shown in copper. Change η and function.

§05 Multiple Integration

5.1 — Double Integrals

R f(x,y) dA = limn→∞ Σᵢ f(xᵢ*,yᵢ*) ΔAᵢ

Computes signed volume under the surface z = f(x,y) over region R.

5.2 — Fubini's Theorem

THEOREM — Fubini (iterated integrals)
If f is continuous on the rectangle R = [a,b] × [c,d], then:
R f(x,y) dA = ∫ₐᵇ [∫cd f(x,y) dy] dx = ∫cd [∫ₐᵇ f(x,y) dx] dy
The order of integration may be exchanged. For general (non-rectangular) regions, the limits become functions of the outer variable.

5.3 — Double Integrals in Polar Coordinates

R f(x,y) dA = ∫αβr₁(θ)r₂(θ) f(r cos θ, r sin θ) · r dr dθ
PROOF — The factor r in polar integration
The Jacobian of (x,y) = (r cos θ, r sin θ) is:
∂(x,y)/∂(r,θ) = | cos θ −r sin θ | = r cos²θ + r sin²θ = r
                 | sin θ r cos θ |
So dA = dx dy = |J| dr dθ = r dr dθ.

5.4 — Triple Integrals

E f(x,y,z) dV = ∫∫∫ f(x,y,z) dx dy dz

Applications: mass = ∭ ρ dV, center of mass = (1/M)∭ x·ρ dV, moment of inertia = ∭ r²·ρ dV.

5.5 — Cylindrical & Spherical Coordinates

SystemCoordinatesVolume Element
Cylindricalx = r cos θ, y = r sin θ, z = zdV = r dr dθ dz
Sphericalx = ρ sin φ cos θ, y = ρ sin φ sin θ, z = ρ cos φdV = ρ² sin φ dρ dφ dθ
PROOF — Spherical volume element dV = ρ² sin φ dρ dφ dθ
The Jacobian matrix J = ∂(x,y,z)/∂(ρ,φ,θ) is 3×3:
Row 1: (sin φ cos θ, ρ cos φ cos θ, −ρ sin φ sin θ)
Row 2: (sin φ sin θ, ρ cos φ sin θ, ρ sin φ cos θ)
Row 3: (cos φ, −ρ sin φ, 0)
det(J) = ρ² sin φ (expanding along row 3 and using sin²+cos²=1).

5.6 — The Gaussian Integral via Polar Coordinates

PROOF — ∫−∞ e−x² dx = √π
Let I = ∫−∞ e−x² dx. Then I² = ∫∫ e−(x²+y²) dx dy.
Switch to polar: I² = ∫₀ ∫₀ e−r² r dr dθ = 2π · [−½ e−r²]₀ = 2π · ½ = π.
Therefore I = √π. This integral is fundamental to probability theory and cryptographic Gaussian sampling.

§06 Change of Variables & Jacobians

6.1 — The Jacobian Matrix

For a transformation T : ℝⁿ → ℝⁿ, the Jacobian matrix is:

J = [∂Tᵢ/∂uⱼ]     (n × n matrix of all first partial derivatives)

6.2 — Change of Variables Theorem

THEOREM — Change of Variables in Multiple Integrals
If T : U → R is a C¹ bijection with nonzero Jacobian determinant, then:
R f(x,y) dx dy = ∬U f(T(u,v)) |∂(x,y)/∂(u,v)| du dv
Intuition: The Jacobian determinant measures how T stretches/compresses infinitesimal area elements. A small rectangle du×dv in the (u,v)-plane maps to a parallelogram with area ≈ |det J| du dv in the (x,y)-plane.
This generalizes to n dimensions: dVx = |det J| dVu.

6.3 — Interactive: Jacobian Transformation Visualizer

↑ Left: original (u,v) grid. Right: transformed (x,y) grid. Area distortion = |det J|.

6.4 — Inverse Function Theorem

THEOREM — Inverse Function Theorem
If F : ℝⁿ → ℝⁿ is C¹ and det(DF(a)) ≠ 0, then F is locally invertible near a, with:
D(F⁻¹)(F(a)) = [DF(a)]⁻¹
The Jacobian of the inverse is the matrix inverse of the Jacobian.

6.5 — Implicit Function Theorem

THEOREM — Implicit Function Theorem
Given F(x,y) = 0 with F : ℝ² → ℝ, if F is C¹ near (a,b) with F(a,b) = 0 and Fy(a,b) ≠ 0, then near (a,b) there exists a unique C¹ function y = g(x) such that F(x,g(x)) = 0 and:
dy/dx = −Fx/Fy
Proof: Differentiate F(x,g(x)) = 0 using the chain rule: Fx + Fy·g′(x) = 0, giving g′(x) = −Fx/Fy. Existence follows from the Inverse Function Theorem applied to (x,y) ↦ (x, F(x,y)).

Cryptographic application: The implicit function theorem guarantees that elliptic curves y² = x³ + ax + b have well-defined tangent lines (and thus a group law) wherever 2y ≠ 0 — this is the foundation of ECC point doubling.

§07 Vector Fields

7.1 — Definition

A vector field F : ℝⁿ → ℝⁿ assigns a vector to each point. In ℝ³: F(x,y,z) = Pi + Qj + Rk.

7.2 — Divergence

div F = ∇ · F = ∂P/∂x + ∂Q/∂y + ∂R/∂z

Measures the rate of "expansion" of the field at a point. Positive = source, negative = sink.

7.3 — Curl

curl F = ∇ × F = (Ry−Qz)i + (Pz−Rx)j + (Qx−Py)k

Measures the "rotation" of the field. If curl F = 0, the field is irrotational.

7.4 — Fundamental Identities

PROOF — curl(∇f) = 0 (gradient fields are irrotational)
∇ × (∇f) = (fzy−fyz)i + (fxz−fzx)j + (fyx−fxy)k = 0
by Clairaut's theorem (mixed partials commute).
PROOF — div(curl F) = 0 (curl fields are solenoidal)
∇ · (∇ × F) = ∂/∂x(Ry−Qz) + ∂/∂y(Pz−Rx) + ∂/∂z(Qx−Py)
= Rxy−Qxz + Pyz−Rxy + Qxz−Pyz = 0.

7.5 — The Laplacian

∇²f = div(∇f) = ∂²f/∂x² + ∂²f/∂y² + ∂²f/∂z²

Laplace's equation ∇²f = 0 governs steady-state heat, electrostatics, and gravitational potentials. Solutions are called harmonic functions.

7.6 — Conservative Fields & Potential Functions

THEOREM — F conservative ⟺ ∫ F·dr is path-independent ⟺ F = ∇φ
(⟹) If F = ∇φ, then ∫C F·dr = ∫C ∇φ·dr = φ(B) − φ(A) by FTC, independent of path.
(⟸) If path-independent, define φ(x) = ∫a→x F·dr. Then ∂φ/∂xᵢ = Fᵢ (by choosing a path ending in the xᵢ-direction), so F = ∇φ.
Necessary condition on simply connected domains: curl F = 0.

7.7 — Helmholtz Decomposition

Any sufficiently smooth vector field F can be decomposed:

F = −∇φ + ∇ × A

into a curl-free (conservative) part and a divergence-free (solenoidal) part. This is fundamental in electrodynamics (E and B fields) and fluid mechanics.

§08 Line Integrals

8.1 — Scalar Line Integral

C f ds = ∫ₐᵇ f(r(t)) ‖r′(t)‖ dt

Integrates a scalar function along a curve weighted by arc length.

8.2 — Vector Line Integral (Work)

C F · dr = ∫ₐᵇ F(r(t)) · r′(t) dt

Computes the work done by force F along curve C.

8.3 — Fundamental Theorem for Line Integrals

PROOF — ∫C ∇f · dr = f(B) − f(A)
Let C be parameterized by r(t), t ∈ [a,b], with r(a) = A, r(b) = B.
C ∇f · dr = ∫ₐᵇ ∇f(r(t)) · r′(t) dt = ∫ₐᵇ d/dt[f(r(t))] dt (chain rule)
= f(r(b)) − f(r(a)) = f(B) − f(A) (by FTC).

8.4 — Circulation & Flux in 2D

Circulation: ∮C F · dr = ∮ (P dx + Q dy)
Flux across C: ∮C F · n ds = ∮ (P dy − Q dx)

8.5 — Complex Line Integrals

For f(z) analytic, ∮ f(z)dz = ∮ (u+iv)(dx+idy) connects complex analysis (residues) to real line integrals in ℝ². The Cauchy integral formula is a line integral that recovers all derivatives of f — see the cryptographic applications in §14.

§09 Surface Integrals

9.1 — Parametric Surfaces

A surface S is parameterized by r(u,v) = (x(u,v), y(u,v), z(u,v)) for (u,v) ∈ D.

The normal vector is n = ru × rv.

9.2 — Surface Area

Area(S) = ∬D ‖ru × rv‖ du dv
PROOF — Surface area element
An infinitesimal patch on S is spanned by vectors ruΔu and rvΔv.
This parallelogram has area = ‖(ruΔu) × (rvΔv)‖ = ‖ru × rv‖ ΔuΔv.
Summing over all patches and taking the limit gives the integral.

For z = f(x,y): dS = √(1 + fx² + fy²) dx dy.

9.3 — Scalar Surface Integral

S g dS = ∬D g(r(u,v)) ‖ru × rv‖ du dv

9.4 — Flux Through a Surface

S F · dS = ∬D F(r(u,v)) · (ru × rv) du dv

Measures the flow of F through S. Orientation matters — the sign of ru × rv determines which side is "positive."

9.5 — Flux of Gravitational/Electric Fields

For the inverse-square field F = q r̂/‖r‖², the flux through a sphere of radius R centered at the origin:

S F · dS = ∬ (q/R²) r̂ · r̂ dS = (q/R²) · 4πR² = 4πq

This is Gauss's Law — the flux depends only on the enclosed charge, not the surface shape (proved generally via the Divergence Theorem §12).

9.6 — First & Second Fundamental Forms

The first fundamental form I = E du² + 2F du dv + G dv² where E = ru·ru, F = ru·rv, G = rv·rv encodes the intrinsic metric of the surface. The Gaussian curvature K = (LN−M²)/(EG−F²) from the second fundamental form is invariant under isometry (Gauss's Theorema Egregium).

§10 Green's Theorem

10.1 — Statement

C (P dx + Q dy) = ∬D (∂Q/∂x − ∂P/∂y) dA

Relates a line integral around a simple closed curve C (oriented counterclockwise) to a double integral over the region D it encloses.

PROOF — Green's Theorem (for type I/II regions)
We prove ∮ P dx = −∬ (∂P/∂y) dA; the Q part is analogous.
Let D be a type I region: a ≤ x ≤ b, g₁(x) ≤ y ≤ g₂(x).
−∬D (∂P/∂y) dA = −∫ₐᵇ ∫g₁(x)g₂(x) (∂P/∂y) dy dx = −∫ₐᵇ [P(x,g₂(x)) − P(x,g₁(x))] dx.
Now trace ∮ P dx around C. The bottom (C₁): y = g₁(x), x: a→b, contributes ∫ₐᵇ P(x,g₁(x))dx.
The top (C₂): y = g₂(x), x: b→a (reversed), contributes −∫ₐᵇ P(x,g₂(x))dx.
Sum: ∮ P dx = ∫ₐᵇ P(x,g₁) dx − ∫ₐᵇ P(x,g₂) dx = −∬ (∂P/∂y) dA. ✓
Similarly ∮ Q dy = ∬ (∂Q/∂x) dA. Adding: ∮ (P dx + Q dy) = ∬ (Qx − Py) dA.

10.2 — Area via Green's Theorem

COROLLARY — Area = ½∮ (x dy − y dx)
Set P = −y/2, Q = x/2. Then Qx − Py = ½ + ½ = 1.
Green's: ∬ 1 dA = Area(D) = ½∮ (x dy − y dx).

This is exactly how GPS systems and GIS software compute polygon areas — the Shoelace formula is the discrete version.

10.3 — Green's Identities

First Green's Identity:

D (f∇²g + ∇f·∇g) dA = ∮C f(∂g/∂n) ds

Second Green's Identity:

D (f∇²g − g∇²f) dA = ∮C (f ∂g/∂n − g ∂f/∂n) ds
PROOF — First Green's Identity
Apply Green's theorem to (P,Q) = (−f gy, f gx):
Qx − Py = fxgx + fgxx + fygy + fgyy = ∇f·∇g + f∇²g.
The line integral becomes ∮ f(gxdy + gy(−dx)) = ∮ f(∇g·n) ds = ∮ f(∂g/∂n) ds.

10.4 — Green's Functions

The Green's function G(x;x₀) satisfies ∇²G = δ(x−x₀). In 2D: G = (1/2π)ln‖x−x₀‖. Any Poisson equation ∇²u = f can be solved via u(x) = ∬ G(x;x₀)f(x₀) dA₀. This is how potential fields in cryptographic lattice problems are analyzed.

§11 Stokes' Theorem

11.1 — Statement

∂S F · dr = ∬S (∇ × F) · dS

The line integral of F around the boundary ∂S of an oriented surface S equals the flux of curl F through S. Green's theorem is the special case where S is flat in the xy-plane.

PROOF — Stokes' Theorem (for a graph z = g(x,y))
Let S be the graph z = g(x,y) over region D, parameterized by r(x,y) = (x, y, g(x,y)).
rx = (1, 0, gx), ry = (0, 1, gy), so rx × ry = (−gx, −gy, 1).
S (∇×F)·dS = ∬D (∇×F)·(−gx, −gy, 1) dx dy.
Meanwhile, ∂S lifts to ∂D via r. On ∂D: ∮ F·dr = ∮ [P + Rgx]dx + [Q + Rgy]dy.
Apply Green's theorem in 2D to this expression and expand using the chain rule. After careful bookkeeping (using gxy = gyx), both sides match.

11.2 — Consequences

If curl F = 0 on a simply connected domain, then ∮ F·dr = 0 for every closed curve, so F is conservative (F = ∇φ). This is the 3D extension of the path-independence theorem.

11.3 — Physical Interpretation

In electrodynamics, Faraday's law is Stokes' theorem applied to the electric field:

∮ E · dr = −d/dt ∬ B · dS    (changing magnetic flux induces EMF)

Ampère's law (with Maxwell's correction) is Stokes' for the magnetic field:

∮ B · dr = μ₀ ∬ (J + ε₀ ∂E/∂t) · dS

§12 The Divergence Theorem (Gauss's Theorem)

12.1 — Statement

∂V F · dS = ∭V (∇ · F) dV

The outward flux of F through the closed surface ∂V equals the total divergence of F inside V.

PROOF — Divergence Theorem (for rectangular boxes)
Let V = [a,b]×[c,d]×[e,f] and F = (P,Q,R). Consider the R-component:
∭ (∂R/∂z) dV = ∫ₐᵇ ∫cdef (∂R/∂z) dz dy dx = ∫∫ [R(x,y,f) − R(x,y,e)] dy dx.
The top face (z=f) has outward normal +k, contributing ∬ R(x,y,f) dy dx.
The bottom face (z=e) has outward normal −k, contributing −∬ R(x,y,e) dy dx.
These match. Similarly for the P (x-faces) and Q (y-faces) components.
Summing: ∯ F·dS = ∭ (∂P/∂x + ∂Q/∂y + ∂R/∂z) dV = ∭ ∇·F dV.
General regions follow by decomposition into small boxes + limit.

12.2 — Gauss's Law (Physics)

∯ E · dS = Qenc/ε₀

The total electric flux through any closed surface equals the enclosed charge divided by ε₀. This is the Divergence Theorem applied to Maxwell's first equation ∇·E = ρ/ε₀.

12.3 — The Grand Unified View

TheoremDimensionBoundary ∂InteriorStatement
FTC1D{a,b}[a,b]F(b)−F(a) = ∫ F′ dx
Green2DCurve CRegion D∮ F·dr = ∬ (Qx−Py) dA
Stokes2D→3DCurve ∂SSurface S∮ F·dr = ∬ (∇×F)·dS
Divergence3DSurface ∂VVolume V∯ F·dS = ∭ ∇·F dV

All are instances of the generalized Stokes' theorem: ∫∂Ω ω = ∫Ω dω (see §13).

§13 Differential Forms & the Generalized Stokes' Theorem

13.1 — 0-Forms, 1-Forms, 2-Forms

Differential forms unify all integration theorems into one framework.

k-FormDescriptionExample
0-formScalar functionf(x,y,z)
1-formIntegrated along curvesω = P dx + Q dy + R dz
2-formIntegrated over surfacesη = A dy∧dz + B dz∧dx + C dx∧dy
3-formIntegrated over volumesμ = f dx∧dy∧dz

13.2 — The Wedge Product

The wedge product ∧ is antisymmetric: dx∧dy = −dy∧dx, and dx∧dx = 0.

If ω = Σ aᵢ dxⁱ and η = Σ bⱼ dxʲ, then ω ∧ η = Σ aᵢbⱼ dxⁱ ∧ dxʲ

13.3 — The Exterior Derivative

The exterior derivative d maps k-forms to (k+1)-forms:

d(Σ fᵢ dxⁱ) = Σ (∂fᵢ/∂xⱼ) dxʲ ∧ dxⁱ
PROOF — d² = 0 (the exterior derivative applied twice is zero)
For a 0-form f: df = Σ (∂f/∂xᵢ) dxⁱ.
d(df) = Σᵢ Σⱼ (∂²f/∂xⱼ∂xᵢ) dxʲ ∧ dxⁱ.
For each pair (i,j): the (j,i) term is (∂²f/∂xᵢ∂xⱼ) dxⁱ ∧ dxʲ = −(∂²f/∂xᵢ∂xⱼ) dxʲ ∧ dxⁱ.
By Clairaut: ∂²f/∂xⱼ∂xᵢ = ∂²f/∂xᵢ∂xⱼ, so the (i,j) and (j,i) terms cancel. d²f = 0.

13.4 — Recovering the Classical Operations

ClassicalDifferential Forms
∇f (gradient)df = fxdx + fydy + fzdz   (d on 0-forms)
∇ × F (curl)dω where ω = P dx+Q dy+R dz   (d on 1-forms)
∇ · F (divergence)dη where η = P dy∧dz+Q dz∧dx+R dx∧dy   (d on 2-forms)
PROOF — d on a 1-form gives the curl
Let ω = P dx + Q dy + R dz.
dω = dP∧dx + dQ∧dy + dR∧dz
= (Py dy∧dx + Pz dz∧dx) + (Qx dx∧dy + Qz dz∧dy) + (Rx dx∧dz + Ry dy∧dz)
Using antisymmetry: = (Ry−Qz) dy∧dz + (Pz−Rx) dz∧dx + (Qx−Py) dx∧dy.
This is the curl components as a 2-form.

13.5 — The Generalized Stokes' Theorem

∂Ω ω = ∫Ω

This single equation encapsulates: the Fundamental Theorem of Calculus (Ω = [a,b]), Green's theorem (Ω = region in ℝ²), classical Stokes' (Ω = surface in ℝ³), and the Divergence theorem (Ω = volume in ℝ³).

PROOF — curl(∇f) = 0 and div(curl F) = 0 from d² = 0
curl(∇f) = 0: gradient is d on a 0-form; curl is d on a 1-form. So curl(grad f) = d(df) = d²f = 0.
div(curl F) = 0: curl is d on a 1-form; divergence is d on a 2-form. So div(curl F) = d(dω) = d²ω = 0.
Both identities are the same fact: d² = 0.

13.6 — De Rham Cohomology (Preview)

The quotient space Hk = {closed k-forms} / {exact k-forms} captures the topology of the domain. A nonzero class in H¹ means there exists an irrotational field that is not conservative — because the domain has a "hole." This is why ∇ × F = 0 implies F = ∇φ only on simply connected domains.

§14 Cryptography — Multivariable Calculus in Security

14.1 — Elliptic Curve Cryptography: The Group Law via Calculus

An elliptic curve E: y² = x³ + ax + b defines a group where point addition uses implicit differentiation (a multivariable calculus operation).

PROOF — ECC point doubling via the Implicit Function Theorem
Define F(x,y) = y² − x³ − ax − b. By the Implicit Function Theorem (§6.5), since Fy = 2y ≠ 0, there exists y = g(x) locally with g′(x) = −Fx/Fy = (3x²+a)/(2y).
This slope m = (3x₁²+a)/(2y₁) defines the tangent line at P = (x₁,y₁).
Substituting into E: the tangent meets E at a third point (x₃,y₃) computed algebraically.
The group operation 2P = (x₃, −y₃). Security rests on the ECDLP: given P and kP, recovering k is intractable.

14.2 — Gradient Descent in Machine Learning & Adversarial Cryptanalysis

Neural networks are trained by minimizing a loss function L(θ) over parameter space θ ∈ ℝⁿ using gradient descent: θt+1 = θt − η∇L(θt). This is a direct application of §3 (gradient = steepest descent direction).

Adversarial attacks: To fool a neural network, compute ∇xL and perturb the input: xadv = x + ε · sign(∇xL) (FGSM attack). This is gradient ascent on the loss — maximizing misclassification via calculus.

14.3 — Lattice Cryptography & Gaussian Measures in ℝⁿ

Post-quantum schemes (CRYSTALS-Kyber, Dilithium) sample errors from discrete Gaussians over lattices Λ ⊂ ℝⁿ:

DΛ,σ(x) = ρσ(x) / ρσ(Λ),    ρσ(x) = exp(−π‖x‖²/σ²)

The normalization ρσ(Λ) = Σv∈Λ exp(−π‖v‖²/σ²) is computed via the Poisson summation formula:

Σv∈Λ f(v) = (1/det Λ) Σw∈Λ* f̂(w)

where f̂ is the Fourier transform (a multivariable integral) and Λ* is the dual lattice.

PROOF — The Gaussian is its own Fourier transform
Let f(x) = e−π‖x‖² for x ∈ ℝⁿ. The Fourier transform:
f̂(ξ) = ∫ℝⁿ e−π‖x‖² e−2πix·ξ dx = ∏ⱼ ∫ e−πxⱼ²−2πixⱼξⱼ dxⱼ
Complete the square: −πxⱼ² − 2πixⱼξⱼ = −π(xⱼ + iξⱼ)² − πξⱼ².
Contour shift: ∫ e−π(xⱼ+iξⱼ)² dxⱼ = ∫ e−πt² dt = 1.
So f̂(ξ) = ∏ⱼ e−πξⱼ² = e−π‖ξ‖² = f(ξ). The Gaussian is a fixed point of the Fourier transform.

14.4 — Differential Privacy via Multivariable Sensitivity

For a vector-valued query f : D → ℝⁿ, the ℓ₂-sensitivity is:

Δ₂f = maxD~D′ ‖f(D) − f(D′)‖₂

The Gaussian mechanism adds noise: output = f(D) + N(0, σ²Iₙ) where σ ≥ Δ₂f · √(2 ln(1.25/δ)) / ε for (ε,δ)-differential privacy. The multivariable Gaussian (§5.6) is essential.

14.5 — Homomorphic Encryption & Polynomial Rings

Fully Homomorphic Encryption (FHE) operates on polynomial rings ℤ[x]/(xⁿ+1). The noise growth under multiplication is analyzed via the ℓ₂ norm on coefficient vectors — a multivariable problem. The Kannan embedding reduces decryption to finding shortest vectors in high-dimensional lattices, where gradient-based methods in ℝⁿ provide heuristic attacks (the BKZ algorithm uses Gram-Schmidt orthogonalization, which is multivariable linear algebra).

14.6 — Zero-Knowledge Proofs & Polynomial Commitments

In a ZK-SNARK, a computation is encoded as a Quadratic Arithmetic Program (QAP) — a system of polynomial equations in multiple variables. The prover evaluates these polynomials over an elliptic curve group, using the multivariable chain rule to handle composed polynomial evaluations efficiently. The KZG commitment scheme commits to a polynomial p(x) by evaluating it at a secret point s hidden in an elliptic curve scalar multiplication: C = [p(s)]G, which combines ECC (§14.1) with polynomial evaluation.

14.7 — Information Geometry & Side-Channel Analysis

The space of probability distributions forms a Riemannian manifold with the Fisher information metric:

gij(θ) = E[∂ log p(x|θ)/∂θᵢ · ∂ log p(x|θ)/∂θⱼ]

This is a multivariable inner product on the tangent space of the statistical manifold. In side-channel cryptanalysis, the Fisher metric measures how efficiently power traces reveal a secret key — the Cramér-Rao bound (the inverse of the Fisher information matrix) gives the minimum variance of any unbiased estimator of the key.

PROOF — Cramér-Rao Bound (multivariate)
Let T(X) be an unbiased estimator of θ ∈ ℝⁿ, so E[T] = θ.
Differentiate ∫ T(x)p(x|θ)dx = θ with respect to θⱼ:
∫ T(x) ∂p/∂θⱼ dx = eⱼ. Since ∂p/∂θⱼ = p · ∂log p/∂θⱼ:
Cov(T, ∂log p/∂θⱼ) = eⱼ ⟹ Cov(T, ∇θ log p) = In.
By the multivariate Cauchy-Schwarz: Var(T) ≥ [In] · [Fisher]⁻¹ · [In]ᵀ = [Fisher]⁻¹.
Therefore Var(T) ≥ I(θ)⁻¹ componentwise.
GNU Octave — Cryptographic Multivariable Calculus
% --- 14A: ECC Point Operations on y²=x³+7 (mod 97) (secp-like) ---
p = 97; a = 0; b = 7;
function r = mod_inv(x, p)
  % Extended Euclidean via Fermat's little theorem
  r = 1; base = mod(x, p); exp = p - 2;
  while exp > 0
    if mod(exp, 2) == 1, r = mod(r * base, p); end
    exp = floor(exp / 2); base = mod(base * base, p);
  end
end

P = [15, 13]; % verify: 13²=169≡72, 15³+7=3382≡72 mod 97 ✓
m = mod((3*P(1)^2 + a) * mod_inv(2*P(2), p), p); % tangent slope (implicit diff)
x3 = mod(m^2 - 2*P(1), p); y3 = mod(m*(P(1)-x3) - P(2), p);
printf("ECC: 2·(%d,%d) = (%d,%d) on y²=x³+7 mod %d\n", P(1),P(2),x3,y3,p);

% --- 14B: Gradient Descent (find minimum of Rosenbrock) ---
f  = @(v) (1-v(1))^2 + 100*(v(2)-v(1)^2)^2;
gf = @(v) [-2*(1-v(1))-400*v(1)*(v(2)-v(1)^2); 200*(v(2)-v(1)^2)];
x = [-1.5; 2]; % start point
for k = 1:50000
  g = gf(x); if norm(g) < 1e-8, break; end
  alpha = 0.001;
  while f(x-alpha*g) > f(x) - 1e-4*alpha*(g'*g), alpha = alpha*0.5; end
  x = x - alpha*g;
end
printf("Gradient descent: min at (%.6f,%.6f), f=%.2e, iters=%d\n", x(1),x(2),f(x),k);

% --- 14C: Fisher Information Matrix for Normal Distribution ---
% p(x|μ,σ) = N(μ,σ²), θ=(μ,σ). Fisher = [[1/σ², 0]; [0, 2/σ²]]
sigma = 2.0; N = 100000;
x = sigma*randn(N,1); % sample from N(0,σ²)
% Score functions: ∂log p/∂μ = x/σ², ∂log p/∂σ = -1/σ + x²/σ³
s_mu = x / sigma^2;
s_sigma = -1/sigma + x.^2/sigma^3;
S = [s_mu, s_sigma];
I_hat = (S' * S) / N;  % empirical Fisher
I_exact = [1/sigma^2, 0; 0, 2/sigma^2];
printf("Fisher info (σ=%.1f):\n  Empirical: [[%.4f,%.4f],[%.4f,%.4f]]\n  Exact:     [[%.4f,%.4f],[%.4f,%.4f]]\n", ...
  sigma, I_hat(1,1),I_hat(1,2),I_hat(2,1),I_hat(2,2), I_exact(1,1),I_exact(1,2),I_exact(2,1),I_exact(2,2));

§15 GNU Octave — Multivariable Calculus Laboratory

15.1 — Numerical Gradient & Hessian

GNU Octave — Numerical Gradient (complex-step, n-dim)
function g = num_gradient(f, x, h)
  if nargin < 3, h = 1e-20; end
  n = length(x); g = zeros(n,1);
  for k = 1:n
    e = zeros(n,1); e(k) = h;
    g(k) = imag(f(x + 1i*e)) / h;
  end
end

function H = num_hessian(f, x)
  h = 1e-5; n = length(x); H = zeros(n);
  for i = 1:n
    for j = i:n
      ei = zeros(n,1); ei(i)=h; ej = zeros(n,1); ej(j)=h;
      H(i,j) = (f(x+ei+ej)-f(x+ei-ej)-f(x-ei+ej)+f(x-ei-ej))/(4*h^2);
      H(j,i) = H(i,j); % symmetry (Clairaut)
    end
  end
end

% Test: f(x,y) = x²y + sin(xy)
f = @(v) v(1)^2*v(2) + sin(v(1)*v(2));
x0 = [1; 2];
g = num_gradient(f, x0);
H = num_hessian(f, x0);
printf("∇f(1,2) = [%.6f, %.6f]\n", g(1), g(2));
printf("Hessian:\n  [%.4f  %.4f]\n  [%.4f  %.4f]\n", H(1,1),H(1,2),H(2,1),H(2,2));

15.2 — Jacobian & Change of Variables

GNU Octave — Jacobian Matrix & Determinant
function J = num_jacobian(F, x, h)
  if nargin < 3, h = 1e-7; end
  n = length(x); f0 = F(x); m = length(f0);
  J = zeros(m, n);
  for k = 1:n
    e = zeros(n,1); e(k) = h;
    J(:,k) = (F(x+e) - F(x-e)) / (2*h);
  end
end

% Polar → Cartesian: T(r,θ) = (r cos θ, r sin θ)
T = @(u) [u(1)*cos(u(2)); u(1)*sin(u(2))];
pt = [3; pi/4];
J = num_jacobian(T, pt);
printf("Jacobian at (r=3,θ=π/4):\n  [%.4f  %.4f]\n  [%.4f  %.4f]\n", J(1,1),J(1,2),J(2,1),J(2,2));
printf("det(J) = %.4f (exact: r = %.4f)\n", det(J), pt(1));

15.3 — Double & Triple Integration

GNU Octave — Numerical Multiple Integration
% Double integral: ∬ exp(-(x²+y²)) dA over [-3,3]²
f2 = @(x,y) exp(-(x.^2+y.^2));
I2 = dblquad(f2, -3, 3, -3, 3);
printf("∬ exp(-(x²+y²)) dA = %.8f (exact π = %.8f)\n", I2, pi);

% Triple integral: volume of unit sphere via ∭ 1 dV
% In spherical: ∫₀²π ∫₀^π ∫₀¹ ρ² sin φ dρ dφ dθ
f3 = @(rho,phi,theta) rho.^2 .* sin(phi);
% Use nested quad
I_theta = @(theta) quad(@(phi) arrayfun(@(p) quad(@(rho) rho.^2.*sin(p), 0, 1), phi), 0, pi);
V = quad(I_theta, 0, 2*pi);
printf("Volume of unit sphere: %.6f (exact 4π/3 = %.6f)\n", V, 4*pi/3);

15.4 — Divergence, Curl & Laplacian

GNU Octave — Discrete Vector Calculus Operators
% Numerical div, curl, and Laplacian on a 3D grid
N = 30; h = 2*pi/(N-1);
[X,Y,Z] = meshgrid(linspace(0,2*pi,N));

% Vector field F = (sin(y), sin(z), sin(x))
Fx = sin(Y); Fy = sin(Z); Fz = sin(X);

% Divergence: ∂Fx/∂x + ∂Fy/∂y + ∂Fz/∂z
% For this field: 0 + 0 + 0 = 0 (solenoidal)
[dFxdx] = gradient(Fx, h); % gradient gives partials along each dim
[~,dFydy] = gradient(Fy, h);
[~,~,dFzdz] = gradient(Fz, h);
divF = dFxdx + dFydy + dFzdz;
printf("div F max (should be ≈0): %.6f\n", max(abs(divF(:))));

% Curl: (∂Fz/∂y-∂Fy/∂z, ∂Fx/∂z-∂Fz/∂x, ∂Fy/∂x-∂Fx/∂y)
[~,dFzdy] = gradient(Fz, h); [~,~,dFydz] = gradient(Fy, h);
[~,~,dFxdz] = gradient(Fx, h); [dFzdx] = gradient(Fz, h);
[dFydx] = gradient(Fy, h); [~,dFxdy] = gradient(Fx, h);
curlx = dFzdy - dFydz; curly = dFxdz - dFzdx; curlz = dFydx - dFxdy;
printf("curl F at center: (%.4f, %.4f, %.4f)\n", ...
  curlx(N/2,N/2,N/2), curly(N/2,N/2,N/2), curlz(N/2,N/2,N/2));

% Laplacian of f = sin(x)sin(y)sin(z): ∇²f = -3f
f = sin(X).*sin(Y).*sin(Z);
[fx,fy,fz] = gradient(f, h);
[fxx] = gradient(fx, h); [~,fyy] = gradient(fy, h); [~,~,fzz] = gradient(fz, h);
lap = fxx + fyy + fzz;
exact_lap = -3*f;
printf("Laplacian max error: %.4e\n", max(abs(lap(:)-exact_lap(:))));

15.5 — Line & Surface Integrals

GNU Octave — Line Integral & Green's Theorem Verification
% Verify Green's theorem: ∮(y²dx + x²dy) = ∬(2x-2y)dA over unit disk

% Line integral: parameterize C as (cos t, sin t)
t = linspace(0, 2*pi, 10001); dt = t(2)-t(1);
x = cos(t); y = sin(t);
dx = -sin(t)*dt; dy = cos(t)*dt;
line_int = sum(y.^2.*dx + x.^2.*dy);

% Double integral: ∬(2x-2y)dA in polar
area_int = dblquad(@(r,th) (2*r.*cos(th) - 2*r.*sin(th)).*r, 0, 1, 0, 2*pi);

printf("Green's theorem verification:\n");
printf("  Line integral:   %.8f\n", line_int);
printf("  Double integral:  %.8f\n", area_int);
printf("  Difference:       %.2e\n", abs(line_int - area_int));

15.6 — Laplace's Equation (2D PDE Solver)

GNU Octave — Laplace Solver (Jacobi Iteration)
% Solve ∇²u = 0 on [0,1]² with u=sin(πx) on top, u=0 on other sides
N = 50; h = 1/(N-1);
u = zeros(N,N);
x = linspace(0,1,N);
u(1,:) = sin(pi*x); % top boundary

for iter = 1:5000
  u_old = u;
  u(2:end-1,2:end-1) = 0.25*(u(1:end-2,2:end-1) + u(3:end,2:end-1) + ...
                                 u(2:end-1,1:end-2) + u(2:end-1,3:end));
  if max(abs(u(:)-u_old(:))) < 1e-8, break; end
end

% Exact: u(x,y) = sin(πx)sinh(π(1-y))/sinh(π)
[X,Y] = meshgrid(x, x);
u_exact = sin(pi*X) .* sinh(pi*(1-Y)) / sinh(pi);
printf("Laplace solver: %d iters, max error = %.3e\n", iter, max(abs(u(:)-u_exact(:))));

15.7 — Monte Carlo Integration in Higher Dimensions

GNU Octave — Monte Carlo Volume of n-Ball
% Volume of the unit ball in n dimensions by Monte Carlo
% V_n = π^(n/2) / Γ(n/2 + 1)
for n = [2, 3, 5, 10, 20]
  N_samples = 1e6;
  X = 2*rand(N_samples, n) - 1;  % uniform in [-1,1]^n
  inside = sum(X.^2, 2) <= 1;
  V_mc = 2^n * sum(inside) / N_samples;
  V_exact = pi^(n/2) / gamma(n/2 + 1);
  printf("n=%2d: V_mc=%.4f, V_exact=%.4f, ratio=%.4f\n", n, V_mc, V_exact, V_mc/V_exact);
end

15.8 — Stokes' Theorem Numerical Verification

GNU Octave — Verify Stokes' Theorem
% F = (y, -x, z²), curl F = (0, 0, -2)
% Surface: z = 0 disk of radius 1, boundary is unit circle in xy-plane

% Line integral: ∮ F·dr around unit circle (cos t, sin t, 0)
t = linspace(0, 2*pi, 100001); dt = t(2)-t(1);
x = cos(t); y = sin(t);
% F·r' = y·(-sin t) + (-x)·(cos t) + 0
integrand = y.*(-sin(t)) + (-x).*(cos(t));
line_val = sum(integrand)*dt;

% Surface integral: ∬ curl F · dS = ∬ (0,0,-2)·(0,0,1) dA = -2·Area(disk) = -2π
surf_val = -2*pi;

printf("Stokes' theorem:\n  ∮ F·dr = %.8f\n  ∬ curl F·dS = %.8f\n  Error: %.2e\n", ...
  line_val, surf_val, abs(line_val - surf_val));

15.9 — Constrained Optimization (Lagrange Multipliers)

GNU Octave — Lagrange Multiplier Solver
% Maximize f(x,y,z)=xyz subject to x²+y²+z²=3
% ∇f = λ∇g → (yz,xz,xy) = λ(2x,2y,2z)
% Solve: yz=2λx, xz=2λy, xy=2λz, x²+y²+z²=3
% By symmetry: x=y=z=1, λ=1/2, f=1

% Numerical verification via penalty method
penalty = @(v) -(v(1)*v(2)*v(3)) + 1000*(v(1)^2+v(2)^2+v(3)^2-3)^2;
grad_pen = @(v) [
  -v(2)*v(3) + 4000*v(1)*(v(1)^2+v(2)^2+v(3)^2-3);
  -v(1)*v(3) + 4000*v(2)*(v(1)^2+v(2)^2+v(3)^2-3);
  -v(1)*v(2) + 4000*v(3)*(v(1)^2+v(2)^2+v(3)^2-3)];
x = [0.5; 0.5; 0.5];
for k = 1:10000
  g = grad_pen(x); if norm(g)<1e-10, break; end
  x = x - 0.0001*g;
end
printf("Lagrange: max xyz on sphere = %.6f at (%.4f,%.4f,%.4f)\n", ...
  x(1)*x(2)*x(3), x(1), x(2), x(3));
printf("Constraint: x²+y²+z² = %.6f (should be 3)\n", sum(x.^2));

15.10 — Divergence Theorem Verification

GNU Octave — Divergence Theorem Check
% F = (x³, y³, z³), div F = 3x²+3y²+3z² = 3r²
% ∭ div F dV over unit sphere in spherical coords
% = ∫₀²π ∫₀^π ∫₀¹ 3ρ² · ρ² sin φ dρ dφ dθ = 3 · (2π)(2)(1/5) = 12π/5

vol_int = quad(@(rho) 3*rho.^4, 0, 1) * ...
          quad(@(phi) sin(phi), 0, pi) * ...
          quad(@(theta) 1, 0, 2*pi);

% Surface integral: ∯ F·n̂ dS on unit sphere
% n̂ = (sin φ cos θ, sin φ sin θ, cos φ), |dS| = sin φ dφ dθ
% F on sphere: (cos³θ sin³φ, sin³θ sin³φ, cos³φ)
% F·n̂ = cos⁴θ sin⁴φ + sin⁴θ sin⁴φ + cos⁴φ sin φ (... simplified)
surf_int = dblquad(@(phi,theta) ...
  (cos(theta).^4).*(sin(phi).^4) + (sin(theta).^4).*(sin(phi).^4) + ...
  (cos(phi).^4).*sin(phi), 0, pi, 0, 2*pi);

printf("Divergence theorem:\n");
printf("  ∭ div F dV  = %.8f\n", vol_int);
printf("  ∯ F·dS      = %.8f\n", surf_int);
printf("  Exact 12π/5  = %.8f\n", 12*pi/5);

⚡ Quick Reference Card

Core Operations

OperationFormula
Gradient∇f = (fx, fy, fz)
Divergence∇·F = Px + Qy + Rz
Curl∇×F = (Ry−Qz, Pz−Rx, Qx−Py)
Laplacian∇²f = fxx + fyy + fzz
Directional derivDuf = ∇f · u
JacobianJ = [∂Tᵢ/∂uⱼ],   dA = |det J| du dv

Vector Identities

Identity
∇×(∇f) = 0   (curl of gradient = 0)
∇·(∇×F) = 0   (div of curl = 0)
∇×(∇×F) = ∇(∇·F) − ∇²F
∇·(fF) = f(∇·F) + ∇f·F
∇×(fF) = f(∇×F) + ∇f×F
a×(b×c) = b(a·c) − c(a·b)

Integration Theorems

TheoremStatement
Green's∮ (P dx+Q dy) = ∬ (Qx−Py) dA
Stokes'∂S F·dr = ∬S (∇×F)·dS
Divergence∂V F·dS = ∭V ∇·F dV
Line (conserv.)C ∇f·dr = f(B)−f(A)
AreaA = ½∮ (x dy − y dx)
Gen. Stokes'∂Ω ω = ∫Ω

Coordinate Systems

SystemPositionVolume Element
Cartesian(x, y, z)dx dy dz
Polar(r cos θ, r sin θ)r dr dθ
Cylindrical(r cos θ, r sin θ, z)r dr dθ dz
Spherical(ρ sin φ cos θ, ρ sin φ sin θ, ρ cos φ)ρ² sin φ dρ dφ dθ

Second Derivative Test (ℝ²)

D = fxxfyy−(fxyfxxClassification
D > 0> 0Local minimum
D > 0< 0Local maximum
D < 0anySaddle point
D = 0anyInconclusive