Hartree-Fock Notes

Table of Contents

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}\]

In COmputational Physics, Thijssen begins by looking at using non-orthogonal functions to find the eigen energies and eigen wave functions of the potential well. Solving this problem is solving the generalized eigenvecoter problem (GEP), where \(\mathbf{H}\) is a matrix of the Hamiltonian values of non-orthonogal functions (NOFs), \(\mathbf{S}\) is a matrix of the crossterms of the NOFs, and \(\mathbf{C}\) is the matrix of eigenvector of the energy \(E\), or \[ \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} = \text{ Eigenvector of } \mathbf{H} \text{ also, the compents of the linear addition of the NOFs of the eigen wave function} \\ E = \text{ Eigen energy or the eigenvalue associated with } \mathbf{C} \]

The variational method as stated it would be used in the chapter is in fact not used. Instead, the main disccusion of the chapter is the solution to the general eigenvalue problem (GEP): \(\mathbf{HC} = E\mathbf{SC}\).

In the GEP

There

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

Chapter 4 - Hartree-Fock Method

To reach a Hamiltonian for which the eignstates can be found two approximation are made:

In \(\S4.3.1\), to find the wave function of a Helium atom, we start with the hamiltonian with Born-Oppenheimer Approximation, which is \[ \left[ -\frac{1}{2}\nabla_1^2 - \frac{1}{2}\nabla_2^2 - \frac{2}{r_1} - \frac{2}{r_2} + \frac{1}{ \left| \mathbf{r}_1 - \mathbf{r}_2 \right| } \right]\phi(\mathbf{r}_1)\phi(\mathbf{r}_2) = E\phi(\mathbf{r}_1)\phi(\mathbf{r}_2) \]

then multiply by \(\phi(\mathbf{r}_2)\) and integrate with respect to \(d\mathbf{r}_2\)

\[ \left[ -\frac{1}{2}\nabla_1^2 - \frac{2}{r_1} + \int d^3\mathbf{r}_2 \left|\phi(\mathbf{r}_2)\right|^2 \frac{1}{ \left| \mathbf{r}_1 - \mathbf{r}_2 \right|} \right] \phi(\mathbf{r}_1) = E'\phi(\mathbf{r}_1)\]

then \(\int d^3\mathbf{r}_2 \left|\phi(\mathbf{r}_2)\right|^2 \frac{1}{ \left| \mathbf{r}_1 - \mathbf{r}_2 \right|}\) is the Coulomb energy of particle 1 in the electric field generated by the charge density of particle 2

The wave function we have used is called uncorrelated because of the fact that the probablilty \(P(\mathbf{r}_1,\mathbf{r}_2)\) for finding an electron at \(\mathbf{r}_1\) and antoher one at \(\mathbf{r}_2\) is uncoorelated ... This does not mean that electrons do not feel each other: in the dertmination of the spatial function \(\phi\), the interaction term \(\frac{1}{\left|\mathbf{r}_1 - \mathbf{r}_2 \right|}\) have been taken into account. But this interaction has been an averaged way: it is not the actual position of \(\mathbf{r}_2\) that determines the wave funtion for electron 1, but the average charge distribution of electron 2.

\(\S4.3.2\) - A program for calculating the helium ground state

Paremetrize \[\psi(\vec r) = \sum_1^4 C_p\chi_p (\vec r) \] leads directly to \[ \left[ -\frac{1}{2}\nabla_1^2 - \frac{2}{r_1} + \sum_{r,s=1}^4 C_r C_s \int d^3 r_2 \chi_r(\mathbf{r}_2) \chi_s(\mathbf{r}_2) \frac{1}{ \left| \mathbf{r}_1 - \mathbf{r}_2 \right|} \right] \sum_{q=1}^4 C_q \chi_q(\mathbf{r}_1) = E' \sum_{q=1}^4 C_q \chi_q(\mathbf{r}_1) \] multiply from the left by \(\chi_p(\mathbf{r}_1)\) and integrate by \(\mathbf{r}_1\) leads to \[ \sum_{pq} \left( h_pq + \sum_{rs} C_r C_s Q_{prqs} \right) C_q = E' \sum_{pq} S_{pq} C_q \]

The

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 [629]:
#this is just here to make sure that I can plot every time I restart the ipython notebook
using PyPlot

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 [667]:
# used to clobber terms in a matrix with NaN
function squishMatrix(mat; tol = 1e-16)
    sz = size(mat)
    for i = [1:sz[1]]
        for j = [1:sz[2]]
            if ((mat[i,j] = NaN) || (mat[i,j] < tol))
                mat[i,j] = 0
            end
        end
    end
    return matm2_dif = squishMat(m2)
end
Out[667]:
squishMatrix (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)

Infinite Square Well Approximation

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 [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 [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)

Hydrogen Energey and Wave Aprroximation

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 [601]:
#return a domain in r and a range as a LinComb of gaussian waves
function hydrogen_ExactWaves(;r=6, giveMeEig = hydrogen_4BEigen )
    itr = [1:4]
    
    (h_vals,h_vecs) = giveMeEig()
    h_r = linspace(0.0,r,1000)
    
    #sort the eigen values and vectors
    h_perm = sortperm(h_vals)
    
    #create a matrix to store the values of the LinComb
    h_wpd = zeros(1000,4)
    h_rpd = zeros(4)
    
    for i_r = [1:1000]
        
        # for each eigen vector
        for i_e in itr # iterate over the eigenvector values
            for a in itr # iterate over basis functions
                tmp = h_vecs[a, h_perm[i_e] ] * hydrogen4Basis( h_r[i_r] , a )
                if ( (tmp == NaN) || (tmp < 1e-12) ) # squish values that create garbage
                    h_rpd[a] = 0.0
                else
                    h_rpd[a] = tmp
                end
            end
            
            h_wpd[i_r, i_e] = dot( h_rpd, h_vecs[1:,i_e] )
        end
    end
    
    return (h_r, h_wpd, h_vals, h_vecs, h_perm)
        
end

# plot the "exact" solutions to the hydrogen atom wave functions using a Gaussian Type Orbital (GTO)
function hydrogen_PlotExactWaves(;r=6, giveMeEig= hydrogen_4BEigen )
    (h_r, h_wpd, h_vals, h_vecs, h_perm) = hydrogen_ExactWaves(r=r, giveMeEig = giveMeEig)
    
    #plot each exact wave funciton
    for i = [1:4]
        plot(h_r, h_wpd[1:,h_perm[i]], label="Wave $(i)")
    end
    
    legend()
end
Out[601]:
hydrogen_PlotExactWaves (generic function with 1 method)
In [607]:
function hydrogen_GEPEig()
    #overlap matrix S
    hS = hydrogen_4BS(4)
    
    # diagonalize the S matrix
    hEV = eigvecs(hS)
    hs = squishMat(conj(transpose(hEV))*hS*hEV)
    
    hV = hEV* hs^(-1/2)
    
    hH = hydrogen_4BH(4)
    # hEO is the value of Energies and Waves ("orbitals") of hydrogen atom using the method in sec 3.3
    (h_vals,h_vecs) = eig( transpose(hV)*hH*hV )
    
    return (h_vals, hV*h_vecs)
end
Out[607]:
hydrogen_GEPEig (generic function with 1 method)

Hartree-Fock for Helium atom

In [640]:
he_a = [0.298073, 1.242567, 5.782948, 38.474970]
Out[640]:
4-element Array{Float64,1}:
  0.298073
  1.24257 
  5.78295 
 38.475   
In [631]:
function he_basis(r, a)
    return exp( -1* he_a[a] * r^2 )
end 
Out[631]:
he_basis (generic function with 1 method)
In [663]:
# the matrix element generation functions have their indicies increased by one to work with fillMat funciton
function he_s(p,q)
    return sqrt( (pi / ( he_a[p] + he_a[q] ))^3 )
end

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

function he_c(p,q)
    return (-4pi / (he_a[p+1]+he_a[q+1]))
end

function he_h(p,q)
    return he_k(p,q) + he_c(p,q)
end

function he_q(p,r,q,s)
    return ( 2*pi^(5/2) ) / ( (he_a[p] + he_a[q])*(he_a[r]+he_a[s])*sqrt( (he_a[p]+he_a[r]+he_a[q]+he_a[s]) ) ) 
end

#return the hamilton and the overlap matricies
function he_H()
    return fillMat(4,4,he_h)
end

function he_S(N)
    return fillMat(4,4,he_s)
end

function he_Q()
    Q = zeros(4,4,4,4)
    itr = [1:4]
    
    for i = itr
        for j = itr
            for k = itr
                for l = itr
                    Q[i,j,k,l] = he_q(i,j,k,l)
                end
            end
        end
    end
    
    return Q
end
Out[663]:
he_Q (generic function with 1 method)
In [666]:
# a function that returns a 4x4 matrix from a 4x4x4x4 matrix
function he_subQ(Q,r,s)
    tmp = zeros(4,4)
    for i in [1:4]
        tmp[:,i] = Q[:,r,:,s][:,:,i]
    end
    
    return tmp
end

function he_F(;C=eye(4))
    Q = he_Q()
    H = he_H()
    Q_pq = zeros(4,4)
    itr = [1:4]
    
    for r = itr
        for s = itr
            Q_pq += (he_subQ(Q,r,s)*C[r,s])
        end
    end
    
    return squishMat(H + Q_pq)
end
Out[666]:
he_F (generic function with 1 method)

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 [609]:
hV*hEO_1[2]
Out[609]:
4x4 Array{Float64,2}:
  6.1551     -0.0103621  -0.119454   0.0961015
 -1.2402      1.74489    -0.0813295  0.163017 
  0.226412   -0.629196   -0.496216   0.185587 
 -0.0307798   0.0977745   0.205916   0.0737008
In [610]:
inv(hV)*hEO_1[2]
Out[610]:
4x4 Array{Float64,2}:
  0.156974    0.0236075   0.00471771   0.00024572
 -0.0814932   0.50491     0.188538    -0.0685561 
 -0.0546355   0.602586   -1.25256      1.05823   
 -0.0100429  -0.850275    4.29875      5.57183   
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 [570]:
#reduce r range ( r =100 )
hydrogen_PlotExactWaves(r=100)
In [596]:
# r = 10
hydrogen_PlotExactWaves(r=10)
Out[596]:
PyObject <matplotlib.legend.Legend object at 0x1233d5710>
In [595]:
# changed hyrodgen_PlotExactWaves and hydrogen_ExactWaves to dynamically change r
hydrogen_PlotExactWaves(r=6)
Out[595]:
PyObject <matplotlib.legend.Legend object at 0x12339eb10>
In [604]:
hydrogen_PlotExactWaves(r=4)
Out[604]:
PyObject <matplotlib.legend.Legend object at 0x1239d8690>
In [608]:
hydrogen_PlotExactWaves(r=4,giveMeEig=hydrogen_GEPEig)
Out[608]:
PyObject <matplotlib.legend.Legend object at 0x123f83890>
In [634]:
qaz = zeros(4,4,4,4)
Out[634]:
4x4x4x4 Array{Float64,4}:
[:, :, 1, 1] =
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0

[:, :, 2, 1] =
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0

[:, :, 3, 1] =
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0

[:, :, 4, 1] =
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0

[:, :, 1, 2] =
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0

[:, :, 2, 2] =
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0

[:, :, 3, 2] =
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0

[:, :, 4, 2] =
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0

[:, :, 1, 3] =
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0

[:, :, 2, 3] =
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0

[:, :, 3, 3] =
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0

[:, :, 4, 3] =
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0

[:, :, 1, 4] =
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0

[:, :, 2, 4] =
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0

[:, :, 3, 4] =
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0

[:, :, 4, 4] =
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
In [635]:
qaz[1,1,1,1]
Out[635]:
0.0
In [637]:
qaz[:,1,:,1]
Out[637]:
4x1x4 Array{Float64,3}:
[:, :, 1] =
 0.0
 0.0
 0.0
 0.0

[:, :, 2] =
 0.0
 0.0
 0.0
 0.0

[:, :, 3] =
 0.0
 0.0
 0.0
 0.0

[:, :, 4] =
 0.0
 0.0
 0.0
 0.0
In [641]:
qaz = he_Q()
Out[641]:
4x4x4x4 Array{Float64,4}:
[:, :, 1, 1] =
 90.1588    26.0598    3.7349     0.241237 
 26.0598     8.39724   1.3527     0.092246 
  3.7349     1.3527    0.271299   0.0221563
  0.241237   0.092246  0.0221563  0.0026428

[:, :, 2, 1] =
 26.0598    8.39724    1.3527     0.092246  
 13.4535    4.55438    0.791016   0.0565288 
  3.02586   1.10442    0.226207   0.0189789 
  0.232725  0.0890156  0.0214052  0.00256439

[:, :, 3, 1] =
 3.7349    1.3527     0.271299   0.0221563
 3.02586   1.10442    0.226207   0.0189789
 1.45502   0.542351   0.118417   0.0109962
 0.197998  0.0758205  0.0183225  0.0022375

[:, :, 4, 1] =
 0.241237   0.092246   0.0221563  0.0026428 
 0.232725   0.0890156  0.0214052  0.00256439
 0.197998   0.0758205  0.0183225  0.0022375 
 0.0866092  0.0333109  0.0082054  0.00109008

[:, :, 1, 2] =
 26.0598    13.4535     3.02586    0.232725  
  8.39724    4.55438    1.10442    0.0890156 
  1.3527     0.791016   0.226207   0.0214052 
  0.092246   0.0565288  0.0189789  0.00256439

[:, :, 2, 2] =
 8.39724    4.55438    1.10442    0.0890156 
 4.55438    2.54106    0.649788   0.0545635 
 1.10442    0.649788   0.189101   0.0183394 
 0.0890156  0.0545635  0.0183394  0.00248848

[:, :, 3, 2] =
 1.3527     0.791016  0.226207   0.0214052 
 1.10442    0.649788  0.189101   0.0183394 
 0.542351   0.324729  0.0998599  0.0106354 
 0.0758205  0.046527  0.0157126  0.00217198

[:, :, 4, 2] =
 0.092246   0.0565288  0.0189789   0.00256439
 0.0890156  0.0545635  0.0183394   0.00248848
 0.0758205  0.046527   0.0157126   0.00217198
 0.0333109  0.0205277  0.00706223  0.00105984

[:, :, 1, 3] =
 3.7349     3.02586    1.45502    0.197998 
 1.3527     1.10442    0.542351   0.0758205
 0.271299   0.226207   0.118417   0.0183225
 0.0221563  0.0189789  0.0109962  0.0022375

[:, :, 2, 3] =
 1.3527     1.10442    0.542351   0.0758205 
 0.791016   0.649788   0.324729   0.046527  
 0.226207   0.189101   0.0998599  0.0157126 
 0.0214052  0.0183394  0.0106354  0.00217198

[:, :, 3, 3] =
 0.271299   0.226207   0.118417    0.0183225 
 0.226207   0.189101   0.0998599   0.0157126 
 0.118417   0.0998599  0.0543803   0.00914797
 0.0183225  0.0157126  0.00914797  0.00189851

[:, :, 4, 3] =
 0.0221563  0.0189789   0.0109962   0.0022375  
 0.0214052  0.0183394   0.0106354   0.00217198 
 0.0183225  0.0157126   0.00914797  0.00189851 
 0.0082054  0.00706223  0.00417837  0.000933125

[:, :, 1, 4] =
 0.241237   0.232725    0.197998   0.0866092 
 0.092246   0.0890156   0.0758205  0.0333109 
 0.0221563  0.0214052   0.0183225  0.0082054 
 0.0026428  0.00256439  0.0022375  0.00109008

[:, :, 2, 4] =
 0.092246    0.0890156   0.0758205   0.0333109 
 0.0565288   0.0545635   0.046527    0.0205277 
 0.0189789   0.0183394   0.0157126   0.00706223
 0.00256439  0.00248848  0.00217198  0.00105984

[:, :, 3, 4] =
 0.0221563  0.0214052   0.0183225   0.0082054  
 0.0189789  0.0183394   0.0157126   0.00706223 
 0.0109962  0.0106354   0.00914797  0.00417837 
 0.0022375  0.00217198  0.00189851  0.000933125

[:, :, 4, 4] =
 0.0026428   0.00256439  0.0022375    0.00109008 
 0.00256439  0.00248848  0.00217198   0.00105984 
 0.0022375   0.00217198  0.00189851   0.000933125
 0.00109008  0.00105984  0.000933125  0.000476287
In [649]:
qaz[:,:,1,1] 
Out[649]:
4x4 Array{Float64,2}:
 90.1588    26.0598    3.7349     0.241237 
 26.0598     8.39724   1.3527     0.092246 
  3.7349     1.3527    0.271299   0.0221563
  0.241237   0.092246  0.0221563  0.0026428
In [652]:
qaz[:,1,:,1]
Out[652]:
4x1x4 Array{Float64,3}:
[:, :, 1] =
 90.1588  
 26.0598  
  3.7349  
  0.241237

[:, :, 2] =
 26.0598  
 13.4535  
  3.02586 
  0.232725

[:, :, 3] =
 3.7349  
 3.02586 
 1.45502 
 0.197998

[:, :, 4] =
 0.241237 
 0.232725 
 0.197998 
 0.0866092
In [653]:
qaz[:,:,1,2]
Out[653]:
4x4 Array{Float64,2}:
 26.0598    13.4535     3.02586    0.232725  
  8.39724    4.55438    1.10442    0.0890156 
  1.3527     0.791016   0.226207   0.0214052 
  0.092246   0.0565288  0.0189789  0.00256439
In [654]:
qaz[:,1,:,2]
Out[654]:
4x1x4 Array{Float64,3}:
[:, :, 1] =
 26.0598  
  8.39724 
  1.3527  
  0.092246

[:, :, 2] =
 8.39724  
 4.55438  
 1.10442  
 0.0890156

[:, :, 3] =
 1.3527   
 1.10442  
 0.542351 
 0.0758205

[:, :, 4] =
 0.092246 
 0.0890156
 0.0758205
 0.0333109
In [655]:
qaz[:,1,:,2][:,:,1]
Out[655]:
4x1 Array{Float64,2}:
 26.0598  
  8.39724 
  1.3527  
  0.092246
In [656]:
qaz[:,1,:,2][:,:,2]
Out[656]:
4x1 Array{Float64,2}:
 8.39724  
 4.55438  
 1.10442  
 0.0890156
In [657]:
qua = zeros(4,4)
for i in [1:4]
    qua[:,i] = qaz[:,1,:,2][:,:,i]
end
In [658]:
qua
Out[658]:
4x4 Array{Float64,2}:
 26.0598    8.39724    1.3527     0.092246 
  8.39724   4.55438    1.10442    0.0890156
  1.3527    1.10442    0.542351   0.0758205
  0.092246  0.0890156  0.0758205  0.0333109
In [661]:
qaz[:,1,:,1]
Out[661]:
4x1x4 Array{Float64,3}:
[:, :, 1] =
 90.1588  
 26.0598  
  3.7349  
  0.241237

[:, :, 2] =
 26.0598  
 13.4535  
  3.02586 
  0.232725

[:, :, 3] =
 3.7349  
 3.02586 
 1.45502 
 0.197998

[:, :, 4] =
 0.241237 
 0.232725 
 0.197998 
 0.0866092
In [665]:
Out[665]:
5-element Array{Float64,1}:
 1.0
 1.0
 1.0
 1.0
 1.0
In []: