This Demonstration shows the variational principle applied to the quantum particle-in-a-box problem. The Hamiltonian describing the particle is

, and the eigenfunctions and eigenvalues are given by

and

, respectively. If

is a trial wavefunction that depends on the variational parameter

, then minimizing the energy functional

with respect to

leads to an estimate for the energy. In this example, the values of

that minimize

are

and

,

. The left panel shows the energy estimate and the three lowest eigenenergies, where the red

are located at the

, and the right graphic shows the normalized trial wavefunction for the ground and second excited states, which are the lowest even functions with respect to the central point.