The Calculus of Variations in Maple 8
Copyright 2002 Waterloo Maple Inc
Introduction
The new
VariationalCalculus
package provides routines for solving problems in the calculus of variations, which studies nature's most "efficient" curves and surfaces. Classical problems from the calculus of variations include:

Find the shortest path between two points on a 3D surface, such as a cone (a geodesic problem).

Shape a ramp between two heights such that a ball rolling down it reaches the bottom in minimum time (the Brachistochrone problem).

Find the shape of a soap film having minimum surface area spanning a given wire frame.
Such problems can often be solved with the EulerLagrange equation, which generalizes the Lagrange Multiplier Theorem for minimizing functions of real variables subject to constraints. The EulerLagrange equation is easy to write down in general but notoriously difficult to write down and solve for most practical problems. The
VariationalCalculus
package automates the construction and analysis of the EulerLagrange equation.
Example: The Brachistochrone Problem
The Brachistochrone problem can be stated as follows:
Given two endpoints in the plane, find the curve y(x) between them such that a ball of unit mass rolls along the curve under the influence of gravity in minimum time.
> 
with(VariationalCalculus);

First we write down the falling time over an infintesimal distance
dx
in terms of
y(x)
and
yInit
, assuming the gravitational constant is 1. This is found in standard textbooks on classical mechanics.
> 
fallTime := sqrt( (1+diff(y(x),x)^2)/(2*(yInity(x))) );

We then use the
EulerLagrange
function to compute the EulerLagrange equations for this functional in terms of
y(x)
and its derivatives. This returns a set of ODEs.
> 
EL := EulerLagrange( fallTime, x, y(x) ) ;

Extract the first ODE from the list
> 
ODE1 := remove(has, EL, diff(y(x),x,x))[1];

Compute
y(x)
as a parametric curve
(x(s), y(s))
using the
dsolve
command with the
parametric
option.
> 
sol := dsolve(ODE1, parametric, y(x));

> 
sol := subs( {_T=s}, sol);

Specify the endpoints of the curve:
(0,1)
and
(1, 1/2)
> 
xInit := 0; yInit := 1; xEnd := 1; yEnd := 1/2;

The parameter
s
is not equivalent to time
t
, so we must solve for the value of
s
at which
Use the endpoints to solve for the unknown constants
K[1]
and
_C1
> 
_C1 := solve(subs({s=sEnd}, x(s)) = xEnd, _C1);

The finitelength curve
(x(s), y(s))
is parametrized over
, so
> 
limit(x(s), s=infinity);

> 
K[1] := fsolve( % = xInit, K[1]);

The path along which a ball would roll in minimum time under the influence of gravity. The result is surprising because the curve actually dips below the right end point.
> 
plot([x(s),y(s), s=10..10], xInit..xEnd, 0..yInit);
