Topic

Change of variables, potentials, Lagrange multipliers

Three more tools from the same chapter of the course. changeOfVariables transforms a multiple integral and shows the Jacobian it used. potential decides whether a vector field is a gradient and finds the function it is the gradient of. lagrange finds the candidates for constrained extremes and proves each one exists.

Change of variables

If TT maps a region SS one-to-one onto T(S)T(S), then

∬T(S)f(x,y) dx dy  =  ∬Sf(T(u,v)) ∣det⁡T′(u,v)∣du dv. \iint_{T(S)} f(x, y)\,dx\,dy \;=\; \iint_S f\bigl(T(u, v)\bigr)\,\left|\det T'(u, v)\right| du\,dv .

The factor ∣det⁡T′∣|\det T'| is the local ratio of areas, and forgetting it is the classic mistake. The function returns the matrix, its determinant, and the new integrand, so the step is visible.

const c = changeOfVariables("x^2 + y^2", ["x", "y"],
  { x: "r*cos(t)", y: "r*sin(t)" }, ["r", "t"], { r: [0, 1], t: [0, "2*pi"] });
c.jacobian;      // [["cos(t)", "-(r*sin(t))"], ["sin(t)", "r*cos(t)"]]
c.determinant;   // "r"       (cos² + sin² has been used)
c.sign;          // "positive on the region"
c.integrand;     // "r^3"
c.value;         // an interval around π/2

The sign of the determinant is proven on the region before the absolute value is dropped; if it changes sign there, abs(…) stays in the integrand and sign says so. With { original: region }, the integral is also computed directly in the old variables and agree reports that the two enclosures meet. Three variables work the same way (cylindrical and spherical coordinates).

Conservative fields and potentials

A field F\mathbf F is conservative when F=∇φ\mathbf F = \nabla\varphi for some function φ\varphi, its potential. Then line integrals depend only on the end points: ∫CF⋅dr=φ(B)−φ(A)\int_C \mathbf F\cdot d\mathbf r = \varphi(B) - \varphi(A). On a region without holes the test is ∇×F=0\nabla\times\mathbf F = 0 (in the plane, ∂Q/∂x=∂P/∂y\partial Q/\partial x = \partial P/\partial y).

const p = potential(["2*x*y + z", "x^2", "x + 3*z^2"], ["x", "y", "z"]);
p.conservative;        // true: every component of the curl multiplies out to 0
String(p.potential);   // "x^2*y + x*z + z^3"
p.check;               // ["0", "0", "0"]: each ∂φ/∂xᵢ − Fᵢ
p.value([1, 2, 3]);    // 32 = φ(1, 2, 3) − φ(0, 0, 0), by a certified line integral

const q = potential(["-y", "x"], ["x", "y"]);
q.conservative;        // false
q.witness;             // { point: { x: 1/2, y: 1 }, curl: [2, 2] }: the curl is not 0 there

conservative has three values. It is true when the curl multiplies out to zero identically, false when a certified evaluation finds a point where it is not zero, and null when neither is shown. For polynomial fields the potential is given in closed form, from φ(x)=∫01F(tx)⋅x dt\varphi(\mathbf x) = \int_0^1 \mathbf F(t\mathbf x)\cdot\mathbf x\,dt, and then differentiated as a check. For other conservative fields value(p, from) encloses φ(p)−φ(from)\varphi(p) - \varphi(\text{from}) by the line integral along the segment.

Lagrange multipliers

At an extreme of ff on the set g=0g = 0, where ∇g≠0\nabla g \ne 0, the gradients are parallel: ∇f=λ∇g\nabla f = \lambda\nabla g. Together with g=0g = 0 that is a system of equations for the point and λ\lambda, and it is exactly the statement that the Lagrangian L=f−λgL = f - \lambda g has a critical point in all its variables. So the candidates are found by the certified critical-point search of Several variables, applied to LL.

const r = lagrange("x*y", "x^2 + y^2 - 1", ["x", "y"], { x: [-2, 2], y: [-2, 2] });
r.lagrangian;          // "x*y - lambda_*(x^2 + y^2 - 1)"
r.candidates.length;   // 4, each proven to exist and to be alone in its small box
r.candidates[0];       // { point: { x: […], y: […] }, multiplier: […], value: […], unique: true, proven: true }
r.max;                 // { value: [0.5, 0.5], at: [two points] }
r.min;                 // { value: [-0.5, -0.5], at: [two points] }

Each candidate comes with an interval for every coordinate, for the multiplier and for the value of ff. max and min are the candidates with the largest and smallest values. They are the extremes of ff on the constraint set when that set is closed and bounded, lies inside the box searched, and ∇g\nabla g does not vanish on it. Those are the hypotheses of the method and are not checked by the function. The multiplier is searched in [−16,16][-16, 16] unless you pass { multiplier: [a, b] }.

callreturns
changeOfVariables(f, vars, map, newVars, region, { digits = 8, original }){ jacobian, determinant, sign, factor, integrand, value, direct?, agree? }
potential(F, vars){ conservative, curl, witness, potential, check, value(p, from) }
lagrange(f, g, vars, box, { multiplier, digits = 10 }){ lagrangian, candidates, max, min, complete }
Try itEdit the code and run it with @ratmath/analytic and Core's R, Rational, RationalInterval in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.
Ctrl/⌘ + Enter runs