I have my code written as follow but can not run it because index out of bounds, can someone tell me where I did it wrong?
def potential(a,b,c,d):
energylist = []
for x in np.arange(-5,10,0.1):
for y in np.arange(-5,10,0.1):
expa = np.exp(-(x-a)**2)
expb = np.exp(-(y-b)**2)
expc = np.exp(-(x-c)**2)
expd = np.exp(-(y-d)**2)
if x-y != 0:
integ = expa*expb*(1/np.abs(x-y))*expc*expd
energylist.append(integ)
val = sum(energylist)
return val
def htable(*myions):
k = len(myions)
matrix = np.zeros((k^2,k^2),float)
for i in np.arange(0,k^2-1,1):
for j in np.arange(0,k^2-1,1):
m = myions[i/k]
n = myions[i%k]
o = myions[i/k]
p = myions[i%k]
matrix[i,j] = potential(m,n,o,p)
print matrix
return matrix
htable(1,3)
^
is not the exponentiation operator but the binary exclusive or operator; replace ^
with **
to get the exponentiation. 2 ^ 2 == 0
, which causes your matrix
to have 0 by 0 elements.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.