VariationalTheorem - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim

Approximation Methods: The Variational Theorem

Copyright (c) RDMCHEM LLC 2019



 Interactive Concepts

Applications in Chemistry



A tenant of the Born interpretation of quantum mechanics is that contained within the wavefunction, ψ, is all the information  one can possibly know about a quantum system, where for time-invariant systems, ψ is the solution to the Schrodinger equation.  In this chapter, we consider only time-invariant Hamiltonians and look at solutions to the time-independent Schrodinger equation (TISE), Hψ = Eψ . For all but a handful of systems, which include the particle in a box, the harmonic oscillator, and the hydrogen atom, exact analytical solutions to the TISE are not known, and one must resort to approximate solutions. In this chapter, we explore an extremely important theorem in quantum mechanics known as the Variational Theorem, which provides a means for finding an upper bound to the true energy of a system. 



Consider that we can rewrite the TISE as

E = ψH ψ dxψ ψ dx


where for a normalized wavefunction, the denominator is equal to 1.   Since we do not in general know ψ, let us choose a trial wavefunction, ϕ, as a guess to the solution, where ϕ must obey the same boundary conditions as ψ.  The variational theorem says:


Variational Theorem:  For a trial wavefunction, ϕ, that obeys the boundary conditions of the TISE, then the expectation value of the energy for the trial  wavefunction, hereafter referred to as the variational energy, Ef , given by 


Ef = φH φ dxφ φ dx


is greater than or equal to the true energy, E. That is,   Ef  ≥  E,  where the equality holds only for φ = ψ.    


That is, the energy calculated using the above equation is always greater than the true energy.  If we choose better and better guesses for the trial wavefunction φ, then Ef  will continue to decrease until it converges (within some acceptable tolerance) to the true energy, E!    



In the Interactive Concepts section below, we focus on the particle in a one-dimensional box and consider increasingly more flexible trial wavefunctions to show the power of the variational principle.  In the Applications to Chemistry section, we introduce the Morse oscillator, a more realistic potential for describing vibrational energies of diatomics and apply the variational theorem to approximate the allowed energies.  We also see how electronic structure methods based on the variational method can be used to calculate the energies of atoms and molecules.


 Interactive Concepts


To show the variational theorem in action, we want to consider a quantum system for which we know the correct solutions with which to compare.  For this we choose the beloved 'particle in a box'! (For more on this topic, see the Particle in a Box exercise).  The particle in a box entails a particle with mass m moving in a one-dimensional potential V(x)

V(x) = 0L2<x<L2else&comma;


where L is the length of the box.  The solution to the TISE yields normalized wavefunctions and energies given by


ψ(x) = 2Lsinn&pi;xL&plus;n&pi;2




En = n2h28 mL2&comma;


where h = Planck's constant and n = 1, 2, 3, ....   For simplicity, we will work in atomic units, in which me = Z = e = 4πe0 = 1. The unit for length is the Bohr radius, a0,  the unit for mass is the mass of the electron, me, and the unit for energy is the Hartree, Eh.  Therefore, for an electron in a box of length L = 2 a0, we have


En = n2π28


Now, what should we use as an approximate wavefunction, ϕ?  In what follows we consider as an initial guess the function ϕ(x) =1 - x2 and then explore different methods for improving upon this initial guess.

Trial Wavefunction #1:   φx&equals;1x2


Consider the trial wavefunction φ(x) =1 - x2.    Does 4 obey the boundary conditions of the problem?  


Yes!!  By inspection, the trial wavefunction goes to zero at  x = ± L/2 = ±1.  It is also continuous with a continuous first derivative, making it an acceptable trial wavefunction for this problem!


Using the Maple input below, calculate the energy, Ef, of this trial wavefunction and compare it to the true ground state energy. You may also use the plot function to compare ϕ to the true wavefunction, ψ.


restart &colon; withplots&colon; 


Etrialint&phi;xdiffdiff12 &phi;x&comma;x&comma;x&comma;x&equals;1..1int&phi;x&phi;x&comma;x&equals;1..1












AplotsinPix2&plus;Pi2&comma;x&equals;1..1&comma;color&equals;Red&colon; Bplotphix&comma;x&equals;1..1&comma;color&equals;Blue&colon; displayA&comma;B


In accord with the variational theorem, the energy of the trial wavefunction is higher than the true ground state energy! From the plot of the true wavefunction (red) and the trial wavefunction (blue), we can see that there is room for improvement!  Can you think of another trial wavefunction that could be tried?  Enter your trial wavefunction for ϕ(x) in the Maple input above to see if your trial wavefunction is better than 1-x2. Remember, your trial wavefunction must obey the original boundary conditions!


Trial Wavefunction #2:   &phi;x&equals;1x2+ &beta;x2x4


     One way to add flexibility to a trial wavefunction is to add a 'variational parameter'.  Consider the trial wavefunction given by


φ(x ; β) =1 - x2+ β (x2 - x4)


where (x ; β) implies that ϕ is a function of x and parameterized by the variational parameter β. That is, we want to find the value of β that gives us the best trial wavefunction of the form given above.  Given the infinite possibilities for β, how are we to proceed?    A conceptual way is to use Maple's interactive plot feature to plot both ψ(x) (the true wavefunction, red) and ϕ(x ; β) (blue), vary β until the two plots match, and then use the variational method to calculate the energy!  


restart &colon; withplots&colon; 


&psi;x  sinπx2&plus;π2&colon;






Enter the value of β that allowed for the best match between the trial and true wavefunctions below to see the new trial energy:


beta0.256 &colon;

Etrialint&phi;x&comma;&beta;diffdiff12 &phi;x&comma;&beta;&comma;x&comma;x&comma;x&equals;1..1int&phi;x&comma;&beta;&phi;x&comma;&beta;&comma;x&equals;1..1&semi;













Were you able to improve upon the original trial energy?


Yes!  With the optimized beta from the plot above, we find the percent error is only 0.04%, as opposed to the 1.32% from Trial Wavefunction#1.



While varying β and comparing differences in the two wavefunctions is a simple, intuitive approach, it is not generally useful since we do not in practice know the true wavefunction!  A more mathematically rigorous approach is to find the minimum of trial with respect to β by solving



Use the Maple input below to solve for b that minimizes dEφ/db and calculate the resulting variational energy to compare with the value that you were able to find from the plot above.


restart &colon;


Etrialint&phi;x&comma;&beta;diffdiff12 &phi;x&comma;&beta;&comma;x&comma;x&comma;x&equals;1..1int&phi;x&comma;&beta;&phi;x&comma;&beta;&comma;x&equals;1..1&colon;







Here we see two solutions, one very close to what was seen from the plot approach above!  Plug in each value to the expression for the variational energy to see which is the 'global' minimum!




Etrialint&phi;x&comma;&beta;diffdiff12 &phi;x&comma;&beta;&comma;x&comma;x&comma;x&equals;1..1int&phi;x&comma;&beta;&phi;x&comma;&beta;&comma;x&equals;1..1&semi;













Which value of b yielded the minimum energy?


We find that β = -0.22075 is the absolute best value for β, and that for the functional form  φ(x ; β) =1 - x2+ β (x2 - x4) for the trial wavefunction, 0.00147% error is the best that we can do!

Trial Wavefunction #3:   &phi;x&equals;&alpha;1x2+ &beta;x2x4


In order to improve further upon our trial wavefunction, we can increase the number of variational parameters.  This method will be used in the Applications in Chemistry section below to estimate the ground and excited state energies for the Morse Oscillator.  The equations generated for this multivariational approach are provided in the subsection below.  The Maple input relies on the expressions introduced therein.


Linear Combinations of Basis Functions for the Trial Wavefunction, 4


     This subsection explores the equations encountered when the trial wavefunction is a linear combination of basis functions.  It is the background information for Interactive Concepts: Trial Wavefunction #3 and Chemical Applications: The Morse Oscillator.  


Consider as a trial wavefunction a linear combination of N basis functions g1,  g2, ..., gN, each of which satisfying the boundary conditions of the system:


φ(x) = c1 g1(x) + c2 g2 (x) + ⋅⋅⋅ + cN gN (x).


The set of expansion coefficients  c1, c2, ..., cN, become variational parameters! It can be shown that the above expression for φ(x) leads to a generalized matrix equation:


Hc = Ef Sc

where Ef is the variational energy,  c is the column vector with elements c1, c2, ..., cN, H and S are N × N matrices with matrix elements given by


Hij = gi Hgj &DifferentialD;x


Sij = gi gj &DifferentialD;x.


The S matrix is known as the overlap matrix and reduces to the identity matrix for an orthonormal basis set.  The matrix equation above leads to a set of linear equations that have a non-trivial solution if and only if

det [ H - Ef S] = 0


For a linear combination of N basis functions, one gets an N-order polynomial expression for the energy Eφ, and it can be shown that the ordered set of Eφ is an approximation to the ordered set of Etrue ground and excited states!  


Consider the trial wavefunction

φ(x) = c1( 1 - x2) + c2 ( x2 - x4),


We know we must solve the set of equations given by

det H11  E&phi; S11   H12  E&phi; S12H21  E&phi; S21H22  E&phi; S22&equals; 0


The solution to the above equation gives rise to a quadratic equation for Ef . The smaller of the two solutions is an upper-bound to the ground state, and the larger of the two solutions is an upper bound to the first even excited state!  Why is it not an approximation to the very first excited state?


Since (1 - x2) and (x2 - x4) are both even functions, and any linear combination of two even functions is still even.  The first excited state is an odd function, which cannot be approximated by an even function!


Use the Maple input below to calculate the ground and first even excited states of the particle in a box and compare them to the true values.




g2 x2 x4&colon;



















Compare this answer to the optimal value of Trial Wavefunction #2.  Is it better?  How good is the 12.766 value to the first even (n = 3) excited state?  



Error12.76628130  EtrueEtrue100






We find that this is a very poor approximation to the n = 3 state (or the first even excited state)!  What could be done to improve this result??


Use more basis functions in the linear combination!

Applications in Chemistry

  Morse Oscillator and the Vibrational Energies of HCl


     In the section above, we used the variational theorem to approximate the energies of the particle in a box, and we saw that the use of variational parameters can be used to get us quite close to the true energy of the system.  In this section, we consider a slightly less trivial system: the Morse oscillator, which can be used to model a vibrating diatomic molecule. We consider the use of trial wavefunctions that are linear combinations of underlying basis functions, as seen in Interactive Concepts: Trial Wavefunction #3.  While the math may be more involved, the underlying ideas of the variational theorem hold: as long as a trial wavefunction ϕ satisfies the boundary conditions of the Hamiltonian, then the expectation value of the energy for ϕ will be higher than the true energy, and as more basis functions and variational parameters are used in the approximation, the better the energy will be.


The Morse potential is an analytical function for the potential energy that includes anharmonicity for diatomic vibrations and is given by


V(r) = De { 1 - exp(-β (r - r0))}2


where De is the well depth, r - r0 is the displacement from the equilibrium bond length r0, and β is a molecular parameter related to the force constant of the molecule.   Table 1 contains a list of these parameters for HCl, which are determined by fitting the potential to spectroscopic data.  Also contained in Table 1 are the first two actual energies of the Morse oscillator and the corresponding fundamental frequency in wavenumbers.   This can be compared with the observed fundamental frequency.



Table 1: Morse Parameters for HCl




2.409 a0


0.9890 a0-1


0.1697 Eh


1785.7 me


0.006749 Eh


0.01984 Eh


2827.2916 cm-1


2885.9 cm-1




Use the Maple input below and the information from Table 1 to generate the Morse potential for HCl.


withplots&colon; plot0.16971  exp0.9890r  2.409 2&comma;r&equals;1..10&comma;y&equals;0..0.5


The Hamiltonian for the Morse oscillator in atomic units is given by


H&equals; 12 &mu;d2dx2&plus;De  1  exp&beta; x2

where x is the displacement from equilibrium distance, and m is the reduced mass of HCl (1H35).   While an analytic series solution does exist for the Morse oscillator, we will use the variational method to calculate approximate solutions.  We will choose as a trial wavefunction a linear combination of N basis functions:


φ(x) = c1g1(x) +  c2g2(x)  + ... +  cNgN(x)


As shown in Interactive Concepts: Trial Wavefunction #3, a linear combination of N basis functions leads to N approximate solutions.  What should we use as basis functions?  Given that we are interested in the ground and low lying vibrational states for which the potential is still rather harmonic, let's try harmonic oscillator wavefunctions as our basis!  


Use the Maple input below to calculate the lowest N states of the Morse oscillator using a basis of N harmonic oscillator functions.   (Recall that the vibrational quantum numbers for the first N states of the harmonic oscillator are v = 0, 1 , 2, 3, ...,  N - 1.)  Begin with N = 2 to get an approximation to the ground and first excited state of the Morse oscillator and compare them with the analytical values provided in Table 1.  Once the energies have been calculated, use them to calculate the fundamental IR vibrational frequency of the HCl molecule in wavenumbers (cm-1) and compare this value with the analytical value from Table 1, 2827.2916 cm-1.                          




r02.409&colon; &beta;0.9890&colon; De0.1697&colon; &mu;1785.7 &colon;k2Deβ2&colon;&alpha;sqrtk&mu;&colon;&omega;sqrtk&mu;&colon;




for i from 0 to N1 by 1 do            gpx&comma;i12&mu;diffdiffgx&comma;i&comma;x&comma;x&plus;Vxgx&comma;i end do&colon;

MMatrixN&comma;N&comma;shape&equals;symmetric &colon;

for i from 0 to N1 by 1 do     for j from i to N1 by 1 do      Mi&plus;1&comma;j&plus;1intgx&comma;igpx&comma;j&comma;x&equals;infinity..infinity end do end do

EEigenvaluesMatrixM&comma;shape&equals;symmetric&colon;for i from 1 to N by 1 do Ei end do





















PercentErrorabs2827.2916 Fundamental2827.2916100





With only 2 basis functions, we actually get a pretty good approximation to both the ground and 1st excited state, with 0.5% and 6.9%, respectively!   Why do you think the agreement is so good?


For low lying states, the Morse potential is fairly harmonic, so the harmonic oscillator basis functions are very good approximations to the ground and first excited states, though we do see that as we increase in energy, the agreement diminishes since more anharmonicity is added to the Morse potential.  Note the approximation to the fundamental frequency is approximately 12%, reflecting the larger error in the first excited state.


Now what happens as you increase N? Do you get better approximations to the ground and first excited state, consistent with the Variational Theorem?   To answer this, N  = 5 in the Maple input and recalculate the approximate energies.


As N increases, we not only get more approximations to excited states, but the approximations get better and better for lower lying states, in accord with the variational theorem. The new errors are only 0.0040% and 0.22% for the ground and first excited state, respectively.  We also note that we get a better approximation to the fundamental frequency, with now only 2% error!  


Now let N = 15 in the Maple input above and recalculate the energies. Note that this might take some time!  Once the energies are calculated, use the Maple input below to explore some of the key quantitative and qualitative differences between the harmonic oscillator and the Morse oscillator.



In the plot below, we show the first 5 states of the harmonic oscillator (red) and the Morse oscillator (blue).  


EHOVector5&colon; for i from 0 to 4 by 1 do EHOi&plus;1&omega;i&plus;0.5 end do&colon;

XVector5&comma;1&colon;YVector5&comma;2&colon;BplotX&comma;EHO&comma; x&equals;0..3&comma;y&equals;0..0.07&comma; tickmarks&equals;0&comma;0&comma;symbolsize&equals;15&comma; style&equals;point&comma;symbol&equals;circle&comma;color&equals;Red&colon;CplotY&comma;E&comma;  symbolsize&equals;15&comma; style&equals;point&comma;symbol&equals;circle&comma;color&equals;Blue&colon; plotsdisplayB&comma;C



XVectorN&comma;r0&colon;AplotDe&comma;x&equals;0..8 &comma;y&equals;0..De&comma; tickmarks&equals;0&comma;0&comma; color&equals;Black&colon;BplotX&comma;E&comma; symbolsize&equals;15&comma; style&equals;point&comma;symbol&equals;circle&comma;color&equals;Blue&colon;CplotDe1exp&beta;xr02&comma;x&equals;0..8&comma;y&equals;0..De&colon; plotsdisplayA&comma;B&comma;C


1) Is the spacing between adjacent energy levels evenly spaced, as seen in the harmonic oscillator?  What happens to this spacing as energy increases?


We see that the energy levels are not evenly space as seen in the harmonic oscillator.  We note that at the bottom of the well, where the approximate energies are more accurate, the spacing decreases for increasing energies.   If we were to use an infinite basis set, we would notice this trend to continue for all states in the well.  The anharmonicity in the potential decreases the energy.


2) Are there an infinite number of 'bound' vibrational energy levels, as seen in the harmonic oscillator? If not, how many bounds states does HCl have?


While there is an infinite number of allowed energy levels in the Morse oscillator, only 12 of these are 'bound'.   One of the key qualitative features of the Morse potential is that it describes bond breaking.  For vibrational states with an energy below De (below the black line in the plot), the wavefunction must decay to zero at large values of x, which implies that the vibration is 'bound'.  That is, the atoms do not have sufficient kinetic energy to overcome the potential attraction, and the bond remains intact.  However, for energies above De, where the kinetic energy is greater than the potential energy at large x, the wavefunction may continue to oscillate at large x (similar to the free particle), and the bond breaks.  In contrast, the harmonic oscillator bond cannot break since its potential energy diverges for increasing x.  This gives rise to an infinite number of bound states for the harmonic oscillator.   


  Variational Calculations of HCl Potential Energy at Equilibrium Bond Distance


In the previous section, we used an analytical fit to the PES for HCl and used the variational principle to calculate the vibrational manifold.  In this section, we actually calculate the potential energy for HCl at its equilibrium bond distance, 2.409 a0.    We will use the Hartree-Fock method, which approximates the true electronic wavefunction as being a single Slater determinant constructed from molecular (spin) orbitals. The MOs are optimized by assuming each electron interacts only through an average electric potential due to all other electrons in the system.   Each MO can be represented in a given basis set, similar to how the vibrational energy levels of HCl were represented in a basis of harmonic oscillator functions.   As the number of basis functions increases, we should see the electronic energy decrease variationally.  


We will explore two series of related basis sets, each of increasing size:  (sto-3g, 6-31g, and 6-311g) and  (cc-pvdz,  cc-pvtz, cc-pvqz, and cc-pv5z).




HClH&comma;0&comma;0&comma;0&comma;Cl&comma;0&comma;0&comma; 2.409&colon;






























For each series, does the energy decrease variationally as the size of the basis increases?  Which series of basis sets gave rise to better energies?   What did notice regarding the time required to carry out each calculation as the size of the basis set increased?


Yes, for the STO-3G, 6-31G, and 6-311G, we notice the energy decreases.  The energy is converged to approximately 0.03 Hartrees, or 17 kcal/mol.    

For the cc-pVDZ,  cc-pVTZ, cc-pVQZ, and cc-pV5Z series, we notice that the cc-pVDZ is consistent with the 6-311G calculation but continues to decrease for increasing basis sizes.   The cc-pV5Z calculation is converged to approximately 0.005 Hartrees, or only 3 kcal/mol and is 12 kcal/mol smaller than the best 6-311G calculation.   


The price one pays for accuracy, however, is time.  The calculations for the larger basis sets were considerably longer.   While the time was not intractable for the HF method, for other more accurate electronic structure methods, this increase can be intractable!