IV. Differential equations and advanced analysis

37. Calculus of variations

The app looks for an extremal of a functional J[y] = ∫ F(x, y, y′) dx with the boundary conditions y(a), y(b): it sets up the Euler–Lagrange equation ∂F/∂y − d/dx ∂F/∂y′ = 0 (with the partial derivatives in the steps), shows the first integral of an integrand without y and solves the resulting differential equation by the ODE solver with the boundary conditions and a check. The problem is also a form in the fields Calculus and Physics (Applications).

If the equation has no closed-form solution and F doesn't depend on x, it uses Beltrami's identity and recognizes the known extremals: the brachistochrone (a cycloid, compared with the straight line, with the time of the slide), the catenary and the minimal surface of revolution (two, one or no catenary – Goldschmidt's solution), an isoperimetric problem with a Lagrange multiplier (a circular arc of a given length, a hanging chain). The constants are found numerically. The principle of least action turns a Lagrangian into the equation of motion, for a pendulum with sin θ ≈ θ. An interactive demo – a race of balls along the brachistochrone – is on mathtrace.app under “Try it yourself”.

How to enter it

functional(sqrt(1 + y'^2); y(0) = 0; y(1) = 2)The integrand and the boundary conditions, separated by semicolons.
functional(y; y(-1) = 0; y(1) = 0; sqrt(1 + y'^2) = pi)The constraint ∫ G dx = L as the last item.
functional(m*x'^2/2 - k*x^2/2; action)A Lagrangian L = T − V and the word action – the equation of motion.

Examples

The shortest path between two points is a segment.
Input: functional(sqrt(1 + y'^2); y(0) = 0; y(1) = 2)
functional(sqrt(1 + y'^2); y(0) = 0; y(1) = 2)
functional(sqrt(1 + y'^2); y(0) = 0; y(1) = 2)functional(sqrt(1 + y'^2); y(0) = 0; y(1) = 2)
The Euler–Lagrange equation y″ = y with boundary conditions.
Input: functional(y'^2 + y^2; y(0) = 0; y(1) = 1)
functional(y'^2 + y^2; y(0) = 0; y(1) = 1)
functional(y'^2 + y^2; y(0) = 0; y(1) = 1)functional(y'^2 + y^2; y(0) = 0; y(1) = 1)
The brachistochrone – a cycloid from A [0; 0] to B [2; 1], a slide of 0.806 s against 1.010 s along the line.
Input: functional(sqrt(1 + y'^2)/sqrt(2*9.81*y); y(0) = 0; y(2) = 1)
functional(sqrt(1 + y'^2)/sqrt(2*9.81*y); y(0) = 0; y(2) = 1)
functional(sqrt(1 + y'^2)/sqrt(2*9.81*y); y(0) = 0; y(2) = 1)functional(sqrt(1 + y'^2)/sqrt(2*9.81*y); y(0) = 0; y(2) = 1)
The minimal surface of revolution between two rings – two catenaries, the shallower is the minimum.
Input: functional(y*sqrt(1 + y'^2); y(-1) = 2; y(1) = 2)
functional(y*sqrt(1 + y'^2); y(-1) = 2; y(1) = 2)
functional(y*sqrt(1 + y'^2); y(-1) = 2; y(1) = 2)functional(y*sqrt(1 + y'^2); y(-1) = 2; y(1) = 2)
Rings far apart – no catenary (Goldschmidt's solution).
Input: functional(y*sqrt(1 + y'^2); y(-2) = 1; y(2) = 1)
functional(y*sqrt(1 + y'^2); y(-2) = 1; y(2) = 1)
The largest area under a curve of length π – a semicircle.
Input: functional(y; y(-1) = 0; y(1) = 0; sqrt(1 + y'^2) = pi)
functional(y; y(-1) = 0; y(1) = 0; sqrt(1 + y'^2) = pi)
functional(y; y(-1) = 0; y(1) = 0; sqrt(1 + y'^2) = pi)functional(y; y(-1) = 0; y(1) = 0; sqrt(1 + y'^2) = pi)
A hanging chain of length 3 – a catenary with a Lagrange multiplier.
Input: functional(y*sqrt(1 + y'^2); y(-1) = 2; y(1) = 2; sqrt(1 + y'^2) = 3)
functional(y*sqrt(1 + y'^2); y(-1) = 2; y(1) = 2; sqrt(1 + y'^2) = 3)
functional(y*sqrt(1 + y'^2); y(-1) = 2; y(1) = 2; sqrt(1 + y'^2) = 3)functional(y*sqrt(1 + y'^2); y(-1) = 2; y(1) = 2; sqrt(1 + y'^2) = 3)
The principle of least action – a spring, the equation of motion m x″ + k x = 0.
Input: functional(m*x'^2/2 - k*x^2/2; action)
functional(m*x'^2/2 - k*x^2/2; action)
functional(m*x'^2/2 - k*x^2/2; action)functional(m*x'^2/2 - k*x^2/2; action)
A pendulum – sin θ ≈ θ for small swings.
Input: functional(m*l^2*θ'^2/2 + m*g*l*cos(θ); action)
functional(m*l^2*θ'^2/2 + m*g*l*cos(θ); action)
functional(m*l^2*θ'^2/2 + m*g*l*cos(θ); action)functional(m*l^2*θ'^2/2 + m*g*l*cos(θ); action)

Known limitations