#calculates the  change in energy
from numpy import *
def delta_e(S,k,J,mu):
	#takes the random site and makes sure its not on the boundaries
	L=size(S,1)
    	k_left=k[0]-1
     	k_right=k[0]+1
     	k_up=k[1]-1
     	k_down=k[1]+1
	
     	if k[0]==0:
     		k_left=L-1
	elif k[0]==L-1:
     		k_right=0
     	if k[1]==0:
		k_up=L-1
	elif k[1]==L-1:
		k_down=0
#energy difference

	E=-2*J*S[k[0],k[1]]*(S[k_left,k[1]]+S[k_right,k[1]]+S[k[0],k_up]+S[k[0],k_down])+mu*S[k[0],k[1]]
	return E
