Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

DEMO: Linear Variational Method

Open in Colab
Source
import numpy as np
from scipy.linalg import eig, inv, eigh
import matplotlib.pyplot as plt
plt.rcParams["figure.dpi"] = 150
from scipy import integrate

Linearizing the problem

Basis sets and coefficients

ϕ(r)=nNcnfn(r)\phi(r) = \sum_n^N c_nf_n(r)

Gaussians are commonly used as basis sets

f(r)=eαr2f(r) = e^{-\alpha r^2}
ϕ(r)=n=1Ncneαnr2\phi(r) = \sum_{n=1}^N c_n e^{-\alpha_n r^2}

Smallest example

ϕ=c1f1+c2f2\phi = c_1f_1 + c_2f_2
Eϕ=ϕH^ϕϕϕ=c1f1+c2f2H^c1f1+c2f2c1f1+c2f2c1f1+c2f2E_\phi = \frac{\langle\phi|\hat{H}|\phi\rangle}{\langle\phi|\phi\rangle} = \frac{\langle c_1f_1 + c_2f_2|\hat{H}|c_1f_1 + c_2f_2 \rangle}{\langle c_1f_1 + c_2f_2|c_1f_1 + c_2f_2 \rangle}

Eigenvalue Problem

[S11S12S12S22]1[H11H12H12H22][c1c2]=E[1001][c1c2]\begin{bmatrix} S_{11} & S_{12} \\ S_{12} & S_{22} \end{bmatrix}^{-1}\begin{bmatrix} H_{11} & H_{12} \\ H_{12} & H_{22} \end{bmatrix} \begin{bmatrix} c_1 \\ c_2 \end{bmatrix} = E \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} \begin{bmatrix} c_1 \\ c_2 \end{bmatrix}

Example: Particle in a Box

H^=22md2dx2\hat{H} = -\frac{\hbar^2}{2m}\frac{d^2}{dx^2}
ψ(x)c1x(ax)+c2x2(ax)2\psi(x) \approx c_1x(a-x) + c_2x^2(a-x)^2
Hij=fiH^fjH_{ij} = \langle f_i|\hat{H}|f_j\rangle
Sij=fifjS_{ij} = \langle f_i|f_j\rangle
H=2a3m[16a230a230a4105]\mathbf{H} = \frac{\hbar^2a^3}{m} \begin{bmatrix} \frac{1}{6} & \frac{a^2}{30}\\ \frac{a^2}{30} & \frac{a^4}{105} \end{bmatrix}
S=a510[13a214a214a463]\mathbf{S} = \frac{a^5}{10} \begin{bmatrix} \frac{1}{3} & \frac{a^2}{14}\\ \frac{a^2}{14} & \frac{a^4}{63} \end{bmatrix}
# Lets adopt simpler units
a = 1.0
hbar = 1.0
m = 1.0

S = np.array([[1.0/30.0, 1.0/140.0],[1.0/140.0,1.0/630.0]])
H = np.array([[1.0/6.0,1.0/30.0],[1.0/30.0,1.0/105.0]])

e, v = eig(inv(S) @ H) #e, v = eigh(H, S) #Same values eigh is for hermitian matrices

print("Eigenvalues:", e)
print("First eigenvector:", v[:,0])
Eigenvalues: [ 4.93487481+0.j 51.06512519+0.j]
First eigenvector: [-0.66168489 -0.74978204]

So we see that the smallest energy in this basis is

Eϕ=4.93492mE_\phi = 4.9349 \frac{\hbar^2}{m}

How does this compare to the analytic solution? Plugging in for the ground state, n=1n=1, and a=1a=1 we get

E1=π2224.93482mE_1 = \frac{\pi^2\hbar^2}{2} \approx 4.9348 \frac{\hbar^2}{m}

So we can see that our variational solution worked out well for the energy. Now how about the wavefunction?

# plot wavefunction
# x values
x = np.arange(0,1,0.01)
# exact wavefunction
psi1Exact = np.sqrt(2)*np.sin(np.pi*x) 
plt.plot(x,psi1Exact,'k-',label="Exact",lw=3)
# variational basis function wavefunction
psi1Var = v[0,0]*x*(1-x) + v[1,0]*x**2*(1-x)**2
norm = np.sqrt(integrate.simpson(np.power(psi1Var,2),x))
plt.plot(x,-psi1Var/norm,'r--', label="Variational")
plt.xlabel('x')
plt.ylabel('$P(x)$')
plt.legend()
<Figure size 960x720 with 1 Axes>