1

I have a set of basis functions defined as:

def HO_wavefunction(x, n, x0, omega, m=1):       
    N = 1.0 / math.sqrt(2**n * math.factorial(n)) * ((m * omega)/(math.pi))**(0.25) # Normaliziation constant
    y = (np.sqrt(m * omega)) * (x - x0)                 
    return N * np.exp(-y * y / 2.0) * sp.hermite(n)(y) 

#Define the basis
def enol_basis(x, n): 
    return HO_wavefunction(x, n, x0=Enolminx, omega=wenol)

I now want to compute the overlap integrals Sii = integral((SiSi)dx), Sjj = integral((SjSj)dx) and Sij = integral((Si*Sj)dx) of my basis functions and store them in some type of array. I tried the following:

G = 10
S = np.empty([G,G])

for n in range (G-1):
    for m in range (G-1):
        S[n][m]= np.trapz(enol_basis(x,n)*enol_basis(x,m),x)
print (S[n][m])

This only returns a single value instead of all the results stored in an array. If anyone could help me compute the overlap integrals as I defined them above and store the results in an array I would really appreciate it!

XBB
  • 109
  • 1
  • 13
  • `print (S[n][m])` is outside of your for loop, so it will only print the element of `S` at the final `n` and `m`. If you indent `print (S[n][m])`, does that resolve your issue? – Angus Williams Oct 27 '16 at 19:37
  • Actually this will fix it. If anyone else runs into this issue: G = 10 S = np.zeros([G,G]) for n in range (G): for m in range (G): S[n][m]= np.trapz(enol_basis(x,n)*enol_basis(x,m),x) print (S) – XBB Oct 27 '16 at 19:39
  • Thank you Angus. I actually just got it! – XBB Oct 27 '16 at 19:40
  • So the issue was what I said, correct? But instead of printing `S[n][m]` in each block of the `for` loop, you just print the whole of `S` afterwards. – Angus Williams Oct 27 '16 at 19:41
  • Yes! That was exactly it – XBB Oct 27 '16 at 19:44
  • Ok. I guess you got it yourself anyway so I won't bother writing up an answer. – Angus Williams Oct 27 '16 at 19:44
  • Thanks for your help! I'm going to leave this here in case anyone else has a similar issue – XBB Oct 27 '16 at 19:46
  • @GloriaBazargan You should write up your solution as an answer and mark it as accepted. That way people see that the problem had a solution. – pingul Oct 28 '16 at 07:47
  • @pingul just did it. thanks! – XBB Oct 28 '16 at 13:31

1 Answers1

1

Solution:

G = 50
S = np.zeros([G,G])

for n in range (G):
    for m in range (G):
        S[n,m]= np.trapz(enol_basis(x,n)*enol_basis(x,m),x)
print (S)
XBB
  • 109
  • 1
  • 13