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 maps a region one-to-one onto , then
The factor 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 is conservative when for some function , its potential. Then line integrals depend only on the end points: . On a region without holes the test is (in the plane, ).
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 , and then differentiated as a check. For other conservative fields value(p, from) encloses by the line integral along the segment.
Lagrange multipliers
At an extreme of on the set , where , the gradients are parallel: . Together with that is a system of equations for the point and , and it is exactly the statement that the Lagrangian has a critical point in all its variables. So the candidates are found by the certified critical-point search of Several variables, applied to .
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 . max and min are the candidates with the largest and smallest values. They are the extremes of on the constraint set when that set is closed and bounded, lies inside the box searched, and does not vanish on it. Those are the hypotheses of the method and are not checked by the function. The multiplier is searched in unless you pass { multiplier: [a, b] }.
| call | returns |
|---|---|
| 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 } |
@ratmath/analytic and Core's R, Rational, RationalInterval in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.