Running the same function twice leads to different plots

18 views
Skip to first unread message

saad khalid

unread,
Jan 10, 2020, 11:08:35 PM1/10/20
to sage-support
Hey everyone:

I'm not quite sure what I'm doing incorrectly here, but I wrote some code which outputs a plot in the end. I start by running:
n =16;
J
= 1;
h
= 1;
var('T,h');
spinConfig
= Tuples([-1,1],n).list()


Then, I run:
def Ham(spins,J,h):
    total
= J*sum(spins[x]*spins[x+1] for x in range(0,len(spins)-1)) + -h * sum(spin for spin in spins)
   
return total

def Partition(spinConfig,T):
   
return sum(e^(-Ham(spins,J,h)/T) for spins in spinConfig)
T
= 1
mag
= (1/n)*derivative(-T*log(Partition(spinConfig,T)),h)
plot
(mag(h),(-10,10))

Now, if I run just this last part a second time, the plot changes! Can anyone tell me what I am doing incorrectly?

Thanks!
Reply all
Reply to author
Forward
0 new messages