Hartree-Fock Notes

Table of Contents

Journal

Documentation

TO DO List

Done

ToBeDone

Computaional Phsyics - J.M. Thijssen

Chapter 3.2 - Variational Method

Start with \[ E\left[ \psi \right] = \frac{\int dX\psi^{*}(X)H\psi(X)}{\int dX\psi^{*}(X)\psi(X)} = \frac{ \left\langle \psi \right| H \left| \psi \right\rangle}{\left\langle \psi | \psi \right\rangle}\]

Through the variational method, we can obtain approximately the correct energy of a Hamiltonian using any basis wave fucntions that satisfy the boundary conditions.

\[ \mathbf{H} = \left\langle \psi_m \right| H \left| \psi_n \right\rangle \\ \mathbf{S} = \left\langle \psi_m \mid \psi_n \right\rangle \\ \mathbf{C} = \ \]

The generalized eigenvalue eqaution \[ \beta_k \mathbf{A}\mathbf{x}_K = \alpha_k \mathbf{B}\mathbf{x}_K \\ k = 0,1,2,...\]

\(\mathbf{HC} = E\mathbf{SC}\) where \(\mathbf{C}\) is the matrix of basis vectors

Code Notes

Relavant Julia Functions and Syntaical Sugar

eye(N)
creates an identity matrix of size \(N\)
eig( M )
computes the eigen values and the eigenvectors of matrix M
inv( M )
computes the inverse of matrix M
M[1:,i]
Returns the ith column of the matrix M
quadgk( f, a, b)
returns the quadrature of the function f over a to b
In [455]:
#this is just here to make sure that I can plot every time I restart the ipython notebook
using PyPlot
whos()
Base                          Module
BinDeps                       Module
Color                         Module
Core                          Module
H_inf                         Function
H_temp                        5x5 Array{Float64,2}
Homebrew                      Module
IJulia                        Module
IPythonDisplay                Module
JSON                          Module
Main                          Module
Nettle                        Module
PyCall                        Module
PyPlot                        Module
REPLCompletions               Module
S_inf                         Function
S_temp                        5x5 Array{Float64,2}
URIParser                     Module
ZMQ                           Module
_1                            Function
_10                           Function
_100                          5-element Array{Float64,1}
_101                          5-element Array{Float64,1}
_102                          Float64
_103                          Float64
_104                          6-element Array{Float64,1}
_105                          Function
_106                          5x5 Array{Float64,2}
_107                          5x5 Array{Float64,2}
_108                          (Array{Float64,1},Array{Float64,2})
_109                          Function
_110                          Function
_111                          (Array{Float64,1},Array{Float64,2})
_112                          5-element Array{Float64,1}
_113                          Function
_114                          (Array{Complex{Float64},1},Array{Complex{Float64},2})
_115                          5-element Array{Complex{Float64},1}
_116                          Int64
_117                          Function
_120                          5-element Array{Complex{Float64},1}
_121                          5-element Array{Float64,1}
_122                          Float64
_123                          5-element Array{Complex{Float64},1}
_124                          Function
_125                          (Array{Float64,1},Array{Float64,2})
_126                          5-element Array{Float64,1}
_127                          Function
_128                          5x5 Array{Float64,2}
_129                          5x5 Array{Float64,2}
_130                          (Array{Float64,1},Array{Float64,2})
_131                          Function
_132                          (Array{Float64,1},Array{Float64,2})
_133                          5-element Array{Float64,1}
_134                          Float64
_136                          5x5 Array{Float64,2}
_137                          Function
_138                          5x5 Array{Float64,2}
_139                          5x5 Array{Float64,2}
_141                          Function
_143                          Function
_144                          Function
_148                          5x5 Array{Float64,2}
_149                          (Array{Float64,1},Array{Float64,2})
_150                          Float64
_151                          6-element Array{Float64,1}
_152                          Float64
_153                          Function
_155                          (Array{Float64,1},Array{Float64,2})
_156                          Function
_157                          (Array{Float64,1},Array{Float64,2})
_158                          Float64
_159                          5x5 Array{Float64,2}
_160                          5x5 Array{Float64,2}
_161                          5x5 Array{Float64,2}
_162                          (Array{Float64,1},Array{Float64,2})
_163                          (Array{Float64,1},Array{Float64,2})
_164                          Function
_165                          (Array{Float64,1},Array{Float64,2})
_166                          5-element Array{Float64,1}
_167                          5-element Array{Float64,1}
_168                          5-element Array{Float64,1}
_169                          Float64
_170                          6-element Array{Float64,1}
_171                          Function
_172                          6-element Array{Float64,1}
_173                          6-element Array{Float64,1}
_174                          Function
_175                          6-element Array{Float64,1}
_176                          8-element Array{Float64,1}
_177                          12-element Array{Float64,1}
_178                          4-element Array{Float64,1}
_179                          5-element Array{Float64,1}
_18                           2x3 Array{Float64,2}
_180                          5-element Array{Float64,1}
_181                          5-element Array{Float64,1}
_182                          (Array{Float64,1},Array{Float64,2})
_183                          (Array{Float64,1},Array{Float64,2})
_186                          8-element Array{Int64,1}
_187                          8-element Array{Int64,1}
_188                          8-element Array{Float64,1}
_189                          8-element Array{Float64,1}
_19                           Function
_190                          (Array{Float64,1},Array{Int64,1})
_195                          Int64
_196                          Int64
_198                          5-element Array{Float64,1}
_199                          6-element Array{Float64,1}
_200                          Int64
_201                          

Code

Globals

In [522]:
#globals used in the Hydrogen 4Basis 
H4B_ALPHA = [13.00773, 1.962079, 0.444529, 0.1219492]
pie3_2 = sqrt( pi^3 )
Out[522]:
5.568327996831708

Macros

Functions

In [463]:
#compose two functions
function myCompose(f,g)
    #given two functions of 1 variable each
    return (x,y)->(f(x)*g(y))
end

function compose(f,g)
    return (x)->(f(x)*g(x))
end
Out[463]:
compose (generic function with 1 method)
In [153]:
# generates the nmth element of the S matrix from CP3.2 
function S_inf(n,m)
    if( (n+m)%2 == 0 )
        return ( (2.0/(n+m+5)) - (4.0/(n+m+3)) + (2.0/(n+m+1)))
    else
        return 0
    end
end

# generates the nmth element of the H matrix from CP3.2
function H_inf(n,m)
    if((n+m)%2 == 0)
        return ( -8.0 * ( (1-m-n-(2m*n)) / ((m+n+3)*(m+n+1)*(m+n-1)) ) )
    else
        return 0
    end
end
Out[153]:
H_inf (generic function with 1 method)
In [458]:
function printMatElem( f, n, m)
    for i in [1:n]
        for j in [1:m]
            temp = f(i,j)
            print("$(temp), ")
        end
        println()
    end
end
Out[458]:
printMatElem (generic function with 1 method)
In [137]:
function fillMat(n,m,f)
    mat = Array(Float64,n,m)
    for i in [1:n]
        for j in [1:m]
            mat[i,j] = f((i-1),(j-1))
        end
    end
    return mat
end
Out[137]:
fillMat (generic function with 1 method)
In [432]:
function infWellEig(n)
    return eig( inv(fillMat(n,n,S_inf))*fillMat(n,n,H_inf) )
end
Out[432]:
infWellEig (generic function with 1 method)
In [460]:
function infWellStatesandEig(n)
    mat = 
    (vals, vecs) = eig(mat)
    return (mat, vals, vecs)
end
Out[460]:
infWellStatesandEig (generic function with 1 method)
In [461]:
# used to clobber terms in a matrix with NaN or less than the tolerance tol
function squishMatrix(mat; tol = 1e-12)
    sz = size(mat)
    for i = [1:sz[1]]
        for j = [1:sz[2]]
            if( (mat[i,j] < tol) || (mat[i,j] = NaN) )
                mat[i,j] = 0
            end
        end
    end
    return matm2_dif = squishMat(m2)
end
Out[461]:
squishMatrix (generic function with 1 method)
In [174]:
function infWellEnergies(n)
    (energies,vecs) = infWellEig(n)
    return sort(energies)
end
Out[174]:
infWellEnergies (generic function with 1 method)
In [477]:
function infWellBasisFuncs(x,n)
    return (x^(n+2))-(x^n)
end

#draws the wave functions
function infWellWavenVec(N; steps = 1000, x_start = -1.0, x_stop = 1.0, eig_vecs=nothing, n = 0)
    #has the user passed any eigenvectors?
    if (eig_vecs == nothing)
        ev = eye(N)
    else
        ev = eig_vecs
    end

    x = linspace(x_start,x_stop,steps)
    wave = 0*Array(Float64,steps)
    for i = [1:steps]
        for j = [1:N]
            bfj_x = infWellBasisFuncs(x[i], (j-1))
            if (bfj_x != NaN) #if the basis function j at x is NaN, skip it or it will create garbage
                wave[i] += ev[j, (n+1)] * bfj_x  #j-1 because the eigenfunctions starts an N=0,1,2,..
            end
        end
    end
    
    return (x,wave)
end
Out[477]:
infWellWavenVec (generic function with 1 method)
In [471]:
# infWellPlotn
function infWellPlotn(N; n = 0, steps = 1000, x_start = -1.0, x_stop = 1.0, eig_vecs=nothing)
    (x,wave) = infWellWavenVec(N,n=n,steps=steps, x_start=x_start, x_stop=x_stop, eig_vecs=eig_vecs)
    
    plot(x,wave)
end
Out[471]:
infWellPlotn (generic function with 1 method)
In [517]:
# quantumWaveKVec 
# description: 
#   generates a vector of the probability density based on the projection into an eigen base
#     N - the number of basis functions, or the order of the approx Matrix
#     domain 
#     basisFunction is a function of two values, position and wave number
#     projectionEigenVector 
function quantumWaveKVec(N, domain, basisFunctions, projectionEigenVector)
    sz = length(domain)
    wave = Array(Float64,sz)
    bfk_x = Array(Float64,N)
    for i = [1:sz]
        for k = [1:N]
            bfk_tmp = basisFunctions(domain[i], (k-1)) 
            if (bfk_tmp != NaN)
                wave[i] += ev[j, (n+1)] * bfj_x  #j-1 because the eigenfunctions starts an N=0,1,2,..
            end
        end
    end
    return wave
end
Out[517]:
quantumWaveKVec (generic function with 2 methods)
In [507]:
# print the energies and Plot the prob densities for an inifite square well with N basis functions
function infSqrWellApproxPlotv1(N; steps = 1000, width = 2.0, center = 0.0, showWhich=-1)
    #step on generate the eigen vectors and values
    (vals, vecs) = infWellEig(N)
    
    #find the order of sorting
    sortOrder = sortperm(vals)
    
    # create the domain and range for the wave functions
    domain = linspace( ((-width/2.0)-center), ((width/2.0)+center), steps)
    projectionEnergy = 0*Array(Float64,N)
    projectionRange = 0*Array(Float64,steps,N) # an Nx1000 matrix for simpelist use
    
    for i in [1:N]
        projectionEnergy[i] = vals[sortOrder[i]]
        projectionRange[1:,i] = quantumWaveKVec(N,domain, infWellBasisFuncs, vecs[1:,sortOrder[i]])
    end
    
    if (showWhich == -2)
        for i in [1:N]
            plot(domain,projectionRange[1:,i])
        end
    elseif (showWhich == -1) #show the first five (default)
        for i in [1:5]
            plot(domain,projectionRange[1:,i], label="Wave $(i-1) with Energy $(round(projectionEnergy[i],4))")
        end
    else
        plot(domain,projectionRange[1:,showWhich])
    end
    if ( sign(projectionRange[ int(steps/2), 1]) == -1)
        legend(loc="lower right")
    else
        legend(loc="upper right")
    end
end
Out[507]:
infSqrWellApproxPlotv1 (generic function with 1 method)
In [513]:
# infWellBasisPlot plots the first 5 orders of the basis wave functions
function infWellBasisPlot(;steps = 1000)
    domain = linspace(-1.0,1.0,steps)
    pRange = 0*Array(Float64,steps,5)
    
    for i = [1:steps]
        for j = [1:5]
            pRange[i,j] = infWellBasisFuncs( domain[i], (j-1) )
        end
    end
    
    for j = [1:5]
        plot(domain, pRange[1:,j], label="Eqn order $(j)")
    end
    
    legend()
end
Out[513]:
infWellBasisPlot (generic function with 1 method)
In [515]:
# calc the prob densities for an inifite square well with N basis functions
function infSqrWellApprox(N; steps = 1000, width = 2.0, center = 0.0)
    #step on generate the eigen vectors and values
    (vals, vecs) = infWellEig(N)
    
    #find the order of sorting
    sortOrder = sortperm(vals)
    
    # create the domain and range for the wave functions
    domain = linspace( ((-width/2.0)-center), ((width/2.0)+center), steps)
    projectionEnergy = 0*Array(Float64,N)
    projectionRange = 0*Array(Float64,steps,N) # an Nx1000 matrix for simpelist use
    
    for i in [1:N]
        projectionEnergy[i] = vals[sortOrder[i]]
        projectionRange[1:,i] = quantumWaveKVec(N,domain, infWellBasisFuncs, vecs[1:,sortOrder[i]])
    end
    
    return (domain, projectionRange, projectionEnergy)
end

# plot the infSqrWellWaveApprox
function infSqrWellApproxPlot(N)
    (d, pR, pE) = infSqrWellApprox(N)
    
    for i in [1:5]
            plot(domain,projectionRange[1:,i], label="Wave $(i-1) with Energy $(round(projectionEnergy[i],4))")
    end
    mid = int(size(pR)[1] /2.0)
    if ( sign(pR[ int(steps/2), 1]) == -1)
        legend(loc="lower right")
    else
        legend(loc="upper right")
    end
end
Out[515]:
infSqrWellApproxPlot (generic function with 1 method)
In [520]:
function hydrogen4Basis(r,a)
    return exp( -1 * H4B_ALPHA[a] * r^2)
end
Out[520]:
hydrogen4Basis (generic function with 1 method)
In [528]:
# the matrix element generation functions have their indicies increased by one to work with fillMat funciton
function hydrogen4BOverlap(p,q)
    return sqrt( (pi / ( H4B_ALPHA[p+1] + H4B_ALPHA[q+1] ))^3 )
end

function hydrogen4BKinetic(p,q)
    return (3.0 * (H4B_ALPHA[q+1]*H4B_ALPHA[p+1]*pie3_2) / sqrt( (H4B_ALPHA[p+1]+H4B_ALPHA[q+1])^5 ))
end

function hydrogen4BCoulomb(p,q)
    return (-2pi / (H4B_ALPHA[p+1]+H4B_ALPHA[q+1]))
end

function hydrogen4BHamiltonian(p,q)
    return hydrogen4BKinetic(p,q) + hydrogen4BCoulomb(p,q)
end

#return the hamilton and the overlap matricies
function hydrogen_4BH(N)
    return fillMat(N,N,hydrogen4BHamiltonian)
end

function hydrogen_4BS(N)
    return fillMat(N,N,hydrogen4BOverlap)
end

function hydrogen_4BEigen(;N=4)
    return eig( inv(hydrogen_4BS(N))*hydrogen_4BH(N) )
end
Out[528]:
hydrogen_4BEigen (generic function with 2 methods)
In []:

Workbench

In [467]:
ffo = myCompose(x->x, x->x)
println(ffo(2,2))
println(ffo(2,4))
println(quadgk(sin,0,pi))
println(quadgk(compose(sin,cos),0,pi))
4
8
(2.0000000000000004,1.7896795156957523e-12)
(-1.7599996763475964e-16,1.6931353163194785e-24)

In [145]:
# test that the H_inf returns values for H matrix
printMatElem( H_inf, 5, 5)
1.6, 0, 0.6857142857142857, 0, 0.38095238095238093, 
0, 0.8380952380952381, 0, 0.5333333333333333, 0, 
0.6857142857142857, 0, 0.5841269841269842, 0, 0.42712842712842713, 
0, 0.5333333333333333, 0, 0.45021645021645024, 0, 
0.38095238095238093, 0, 0.42712842712842713, 0, 0.3667443667443667, 

In [457]:
# test that the S_inf returns values for H matrix
printMatElem( S_inf, 5, 5)
0.15238095238095228, 0, 0.050793650793650835, 0, 0.023088023088023102, 
0, 0.050793650793650835, 0, 0.023088023088023102, 0, 
0.050793650793650835, 0, 0.023088023088023102, 0, 0.012432012432012418, 
0, 0.023088023088023102, 0, 0.012432012432012418, 0, 
0.023088023088023102, 0, 0.012432012432012418, 0, 0.007459207459207445, 

In [160]:
# test fillMat for the S matrix for the infitite sqaure well
S_temp = fillMat(5,5,S_inf)
Out[160]:
5x5 Array{Float64,2}:
 1.06667    0.0        0.152381   0.0        0.0507937
 0.0        0.152381   0.0        0.0507937  0.0      
 0.152381   0.0        0.0507937  0.0        0.023088 
 0.0        0.0507937  0.0        0.023088   0.0      
 0.0507937  0.0        0.023088   0.0        0.012432 
In [161]:
# test fillMat for the H matrix for the infitite sqaure well
H_temp = fillMat(5,5,H_inf)
Out[161]:
5x5 Array{Float64,2}:
 2.66667   0.0       0.533333  0.0       0.228571
 0.0       1.6       0.0       0.685714  0.0     
 0.533333  0.0       0.838095  0.0       0.533333
 0.0       0.685714  0.0       0.584127  0.0     
 0.228571  0.0       0.533333  0.0       0.450216
In [456]:
# do the eigen values match those in the book in table 3.1
eig(inv(S_temp)*H_temp )
# YES THEY DO! but they are out of order
Out[456]:
([87.739192978954,2.4674011087465995,22.293405912300305,9.875388202501913,50.12461179749826],
5x5 Array{Float64,2}:
  0.0210422     0.973655      0.0887464     6.73642e-17   5.46676e-18
  1.04393e-16   3.32149e-16  -1.34362e-16  -0.888314      0.294439   
 -0.44408      -0.227278     -0.828688     -2.91563e-16  -9.2424e-17 
 -1.71033e-17  -1.44698e-16   1.58974e-16   0.459237     -0.95567    
  0.89574       0.0184593     0.55263       5.14205e-17   1.31985e-16)
In [438]:
(m1,v1,e1) = infWellStatesandEig(5)
Out[438]:
(
5x5 Array{Float64,2}:
  2.15625   0.0    -1.21875    0.0     1.40625
  0.0       2.25    0.0      -14.75    0.0    
 -2.0625    0.0   -10.3125     0.0   -48.5625 
  0.0      24.75    0.0       57.75    0.0    
 13.4063    0.0    67.0313     0.0   120.656  ,

[87.739192978954,2.4674011087465995,22.293405912300305,9.875388202501913,50.12461179749826],
5x5 Array{Float64,2}:
  0.0210422     0.973655      0.0887464     6.73642e-17   5.46676e-18
  1.04393e-16   3.32149e-16  -1.34362e-16  -0.888314      0.294439   
 -0.44408      -0.227278     -0.828688     -2.91563e-16  -9.2424e-17 
 -1.71033e-17  -1.44698e-16   1.58974e-16   0.459237     -0.95567    
  0.89574       0.0184593     0.55263       5.14205e-17   1.31985e-16)
In [176]:
infWellEnergies(8)
Out[176]:
8-element Array{Float64,1}:
   2.4674
   9.8696
  22.2074
  39.4892
  63.6045
  94.1186
 219.721 
 324.523 
In [179]:
infWellEnergies(12)[1:5]
Out[179]:
5-element Array{Float64,1}:
  2.4674
  9.8696
 22.2066
 39.4784
 61.6862
In [181]:
infWellEnergies(16)[1:5]
Out[181]:
5-element Array{Float64,1}:
  2.4674
  9.8696
 22.2066
 39.4784
 61.685 
In [431]:
(p,q) = infWellEig(8)
Out[431]:
([219.72077142008197,63.604460435907974,2.467401100273009,22.207367043698664,324.5225360465308,9.869604412985446,39.48924103469794,94.11861850644559],
8x8 Array{Float64,2}:
 -0.00336414    0.00995859   -0.973579     …   3.76297e-17  -5.82057e-19
 -5.36005e-17   2.04382e-16  -1.14955e-16     -0.118367      0.0308264  
  0.133415     -0.258294      0.227523        -6.4854e-16    3.14553e-17
  5.40821e-17  -1.35378e-16   9.76978e-17      0.634629     -0.338502   
 -0.663764      0.808222     -0.019422         1.03154e-15   3.49853e-17
 -1.88843e-16   5.0014e-16   -3.73455e-16  …  -0.716729      0.805546   
  0.735939     -0.529114      0.000832028     -5.94942e-16  -3.11913e-17
  1.61867e-16  -3.85652e-16   2.69398e-16      0.263695     -0.485348   )
In [469]:
# test ploting and 
x_tmp = linspace(-1.0,1.0,100)
w_tmp = 0*Array(Float64,100)
ev_tmp = eye(5)
for i in [1:100]
    for j in [1:5]
        bf = infWellBasisFuncs(x_tmp[i],(j-1))
        if( bf != NaN )
            w_tmp[i] += (ev_tmp[j,1] * bf)
        end
    end
end
plot(x_tmp,w_tmp)
Out[469]:
1-element Array{Any,1}:
 PyObject <matplotlib.lines.Line2D object at 0x11dfc4a10>
In [289]:
infWellWavenVec(5, n=0)
CREATING IDEN MATRIX

Out[289]:
([-1.0,-0.997997997997998,-0.9959959959959961,-0.9939939939939939,-0.991991991991992,-0.98998998998999,-0.987987987987988,-0.9859859859859861,-0.9839839839839839,-0.9819819819819819  …  0.9819819819819819,0.9839839839839839,0.9859859859859861,0.987987987987988,0.98998998998999,0.991991991991992,0.9939939939939939,0.9959959959959961,0.997997997997998,1.0],[NaN,-0.003999995991987894,NaN,-0.011975939903868004,NaN,-0.01991981971961951,NaN,-0.02783163543924286,NaN,-0.03571138706273849  …  NaN,-0.03177551926300692,NaN,NaN,NaN,-0.015951887823759777,NaN,-0.007991975959943748,NaN,2.1560772376e-314])
In [478]:
infWellPlotn(5)
Out[478]:
1-element Array{Any,1}:
 PyObject <matplotlib.lines.Line2D object at 0x11f970ad0>
In [508]:
infSqrWellApproxPlotv1(5)
Out[508]:
PyObject <matplotlib.legend.Legend object at 0x12116aa10>
In [509]:
infSqrWellApproxPlotv1(8)
Out[509]:
PyObject <matplotlib.legend.Legend object at 0x12149cf90>
In [510]:
infSqrWellApproxPlotv1(12)
Out[510]:
PyObject <matplotlib.legend.Legend object at 0x121775c90>
In [511]:
infSqrWellApproxPlotv1(16)
Out[511]:
PyObject <matplotlib.legend.Legend object at 0x1214af1d0>
In [512]:
infSqrWellApproxPlotv1(20)
Out[512]:
PyObject <matplotlib.legend.Legend object at 0x1214e2510>

20 is the last value before the the values start becomming imaginary.

In [514]:
infWellBasisPlot()
Out[514]:
PyObject <matplotlib.legend.Legend object at 0x1217e0f90>
In [530]:
hfoo = hydrogen_4BEigen()
Out[530]:
([21.144365190122507,2.5922995719598134,0.11321392045798667,-0.49927840566748544],
4x4 Array{Float64,2}:
  0.97965      0.00557858   0.214713  0.349323
 -0.197391    -0.939391     0.146186  0.592557
  0.0360358    0.338738     0.891928  0.674597
 -0.00489894  -0.0526385   -0.370125  0.267898)
In [533]:
dot(hfoo[2][1:,1],hfoo[2][1:,2])
Out[533]:
0.20335728640140624
In [534]:
heig = hfoo[2]
Out[534]:
4x4 Array{Float64,2}:
  0.97965      0.00557858   0.214713  0.349323
 -0.197391    -0.939391     0.146186  0.592557
  0.0360358    0.338738     0.891928  0.674597
 -0.00489894  -0.0526385   -0.370125  0.267898
In [539]:
hS = hydrogen_4BS(4)
hEV = eigvecs(hS)
hs = squishMat(conj(transpose(hEV))*hS*hEV)
Out[539]:
4x4 Array{Float64,2}:
 0.0252204  0.0       0.0       0.0   
 0.0        0.301822  0.0       0.0   
 0.0        0.0       3.05486   0.0   
 0.0        0.0       0.0      50.2475
In [540]:
hV = hEV* hs^(-1/2)
Out[540]:
4x4 Array{Float64,2}:
  6.14441    -0.393404  -0.0191167  0.000417942
 -1.34814    -1.66112   -0.197668   0.006267   
  0.278665    0.622276  -0.511165   0.0406339  
 -0.0403299  -0.109011   0.163155   0.134948   
In [542]:
hId = squishMat( transpose(hV)*hS*hV )
Out[542]:
4x4 Array{Float64,2}:
 1.0  0.0  0.0  0.0
 0.0  1.0  0.0  0.0
 0.0  0.0  1.0  0.0
 0.0  0.0  0.0  1.0
In [547]:
hH = hydrogen_4BH(4)
# hEO_1 is the value of Energies and Waves ("orbitals") of hydrogen atom using the method in sec 3.3
hEO_1 = eig( transpose(hV)*hH*hV )
Out[547]:
([21.144365190122492,2.5922995719598143,0.1132139204579868,-0.4992784056674857],
4x4 Array{Float64,2}:
  0.99761     -0.0654547  -0.0194427   0.0105789
 -0.0655159   -0.994985   -0.0450133  -0.0607104
  0.0205515   -0.0217985   0.933579   -0.357117 
 -0.00771639  -0.072421    0.355002    0.932024 )
In [545]:
# this is my method for finding the Enegies and Orbitals by finding the eigens of the inverse of S multiplied by H
hEO_2 = eig( inv(hydrogen_4BS(4)) * hydrogen_4BH(4) )
Out[545]:
([21.144365190122507,2.5922995719598134,0.11321392045798667,-0.49927840566748544],
4x4 Array{Float64,2}:
  0.97965      0.00557858   0.214713  0.349323
 -0.197391    -0.939391     0.146186  0.592557
  0.0360358    0.338738     0.891928  0.674597
 -0.00489894  -0.0526385   -0.370125  0.267898)
In [553]:
#now find the difference between the two methods
hDiff = hEO_2[2]-hEO_1[2]
Out[553]:
4x4 Array{Float64,2}:
 -0.0179601   0.0710333   0.234156    0.338744
 -0.131875    0.0555946   0.1912      0.653267
  0.0154843   0.360536   -0.0416509   1.03171 
  0.00281745  0.0197825  -0.725126   -0.664127
In [557]:
cos(-pi/4)^2
Out[557]:
0.5000000000000001
In []: