Skip to content

Instantly share code, notes, and snippets.

@prcastro
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prcastro/3e1b8eba78fb7796ba90 to your computer and use it in GitHub Desktop.
Save prcastro/3e1b8eba78fb7796ba90 to your computer and use it in GitHub Desktop.
hb_diagram for Ising Module
# Phase diagram (magnetization by temperature) using heat bath algorithm
function hb_diagram(;n::Int=20, m::Int=50, max::Float64=6.0, h::Float64 = 0.0, iters::Int=50000, ε::Float64 = 0.001, plot::Bool=true, verbose::Bool=true)
temps = Array(Float64, n)
mags = Array(Float64, n)
i = 1
for temp in linspace(0.5, max, n)
avgmag = mean([heatbath!(spinarray(n), h=h, temp=temp, iters=iters, ε=ε, plot=false, verbose=false)[end] for i in 1:m])
if verbose println("(T=$temp) Avg. magnetization after heat bath $avgmag") end
temps[i] = t
mags[i] = avgmag
i += 1
end
if plot
PyPlot.plot(temps, mags, "o", color="blue")
PyPlot.plot(temps, mags, "-", color="blue")
PyPlot.title("Phase Diagram (Heat Bath")
PyPlot.savefig("Plots/diag.png")
PyPlot.close()
end
return mags, temps
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment