do
M=0 before the for loops then where you are computing them do M += ?
Phi Kappa Chi ΦΚΧ <a:yeah:589703000977571860><a:ppHop:536353159615086612>
M=0 before the for loops then where you are computing them do M += ?from math import sqrt
import numpy as np
import matplotlib.pyplot as plt
def centeredgen(L):
for i in range(L+1):
for j in range(L+1):
for k in range(L+1):
yield i,j,k
if k > 0:
yield i,j,-k
if j > 0:
yield i,-j,k
if k > 0:
yield i,-j,-k
if i > 0:
yield -i,j,k
if k > 0:
yield -i,j,-k
if j > 0:
yield -i,-j,k
if k > 0:
yield -i,-j,-k
if __name__ == "__main__":
L = 30
M = 0.0
a = []
gen = centeredgen(L)
next(gen) # skip the 0,0,0
sign2 = lambda n: " " if n >= 0 else ""
sign = lambda n: " "*(3-len(str(n)))
for i,j,k in gen:
h = ((-1.0)**(i+j+k))/sqrt(i*i+j*j+k*k)
M += h
a += [M]
print("%s%d,%s%d,%s%d -> %s%01.4f => %s%01.4f"%(sign(i),i,sign(j),j,sign(k),k,sign2(h),h,sign2(M),M))
print("\nMean estimate: %.4f" % np.mean(a))
plt.plot(a)
plt.show()