This is documentation for Mathematica 5, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)

Documentation / Mathematica / Add-ons & Links / Standard Packages / Calculus /


The basic problem of the calculus of variations is to determine the function that extremizes a functional . In general, there can be more than one independent variable and the integrand can depend on several functions and their higher derivatives.

The extremal functions are solutions of the Euler(-Lagrange) equations that are obtained by setting the first variational derivatives of the functional with respect to each function equal to zero. Since many ordinary and partial differential equations that occur in physics and engineering can be derived as the Euler equations for appropriate functionals, variational methods are of general utility.

First variational derivatives and Euler equations.

VariationalD gives the first variational derivatives of a functional defined by the integrand . may depend on several functions ; their derivatives of arbitrary order; and variables . EulerEquations returns the Euler(-Lagrange) equations given the integrand . Again may depend on several functions ; their derivatives of arbitrary order; and variables .

This loads the package.

In[1]:= <<Calculus`VariationalMethods`

This is the first variational derivative of .

In[2]:= VariationalD[y[x] Sqrt[1+y'[x]^2], y[x], x]


Here is the Lagrangian for the simple pendulum and EulerEquations gives the pendulum equation.

In[3]:= EulerEquations[
m l^2 theta'[t]^2/2+m g l Cos[theta[t]],
theta[t], t]


This package defines several coordinates systems as well as the Grad function.

In[4]:= <<Calculus`VectorAnalysis`

The default coordinate system is set to Cartesian and the coordinates are set to , , and .

In[5]:= SetCoordinates[Cartesian[x, y, z]];

This generates Laplace's equation.

In[6]:= EulerEquations[
phi[x,y,z], {x,y,z}]


First integrals.

When there is only one independent variable , FirstIntegrals gives conserved quantities in the following cases: (1) if does not depend on a coordinate explicitly, it is referred to as an ignorable coordinate and the corresponding Euler equation possesses an obvious first integral (a conserved generalized momentum), and (2) if depends on and their first derivatives only and has no explicit dependence, FirstIntegrals also returns the first integral corresponding to the Hamiltonian.

The Lagrangian for central force motion has an ignorable coordinate (angular momentum conservation) and is independent of time (energy conservation). FirstIntegrals yields both the first integral corresponding to coordinate and the first integral corresponding to the Hamiltonian.

In[7]:= FirstIntegrals[m(r'[t]^2+r[t]^2 phi'[t]^2)/
2-U[r], {r[t],phi[t]}, t]


The Ritz variational principle affords a powerful technique for the approximate solution of (1) eigenvalue problems where is an operator and is a weight function and (2) problems of the form where is a positive definite operator and is given. A judicious choice for the trial function that satisfies boundary conditions and depends on variational parameters must be given in both cases. For (1) VariationalBound[f,g, u[x,y,... ], x,xmin,xmax, y,ymin,ymax,... , , a,amin,amax, b,bmin,bmax, ... ] extremizes where and . The result is an upper bound on the corresponding eigenvalue and optimal values for the parameters. For (2) VariationalBound[f, u[x,y,... ], x,xmin,xmax,y,ymin,ymax,... , , a,amin,amax, b,bmin,bmax, ... ] extremizes the functional with and yields the value of the functional and the optimal parameters. VariationalBound can also be used to extremize general functionals given appropriate trial functions. NVariationalBound performs the same functions as VariationalBound numerically. It uses the internal function FindMinimum and has the same options and input format for parameters.

Ritz variational bounds.

A trial (wave) function for the 2s state of the hydrogen atom with one node at yields the exact energy in units of Rydbergs. Note that the volume element is included in functional parameters and , and the default range for the parameters is .

In[8]:= VariationalBound[{(-u[r] D[r^2 u'[r],r]/r^2-2u[r]^2/r)r^2,
u[r]^2 r^2},u[r],
{r,0,Infinity},(a-r)E^(-b r),{a},{b}]


The problem of the torsion of a rod of square cross section involves solving where vanishes on the boundary. VariationalBound gives optimal values of parameters for the approximate solution.

In[9]:= VariationalBound[-u[x,y](D[u[x,y],{x,2}]+
D[u[x,y],{y,2}]) -2u[x,y],u[x,y],


The ground state energy of the one-dimensional quantum anharmonic oscillator is determined for the given trial (wave) function by NVariationalBound. Note that the default range for the parameters is and the initial values are specified.

In[10]:= NVariationalBound[
{u'[x]^2+(x^2+x^4)u[x]^2/4, u[x]^2},
u[x], {x,-Infinity,Infinity},
E^(-a x^2)(1+b x^2), {a,0.5},{b,0.1}]