(* Student Name *)
(* July 30, 2018 *)
(* Physics III - Introduction to Statistical Physics *)
(* Assignment 6 - Problem 1*)

(a) Function Definitions

f[x_,y_]:=Sqrt[x^2+y^2]; (*Defines function*)
f[3,4] (*Computes function at value of x = 4*)

? ConstantArray

?Total

?Exp

?For

?RandomInteger

?RandomReal

?If

?AppendTo

?ListPlot

?Part

? Mean

?N

? Tanh

(b) Low Temperature Spin Simulations

(* Parameter Definitions *)
kBT = ...; (*Temperature value*)
mu = ...; (* Magnetic dipole moment value *)
H = ...; (*Magnetic field value*)
Nspns =...; (*Number of spins in system*)
Nstps = ...; (*Number of steps in simulation*)

(*Spin configuration and total spin*)
S0 = ...; (* Definition of initial Spin Configuration*)
Savg = {}; (* Empty vector representing average spin after each simulation *)

(* Energy  of Microststate*) 
Energy[S_] := ...;

(* Boltzmann Factor Ratio; Use Mathematical operator "N" to make sure you get numerical value  *)
BoltzRatio[Sfinal_,Sinitial_] := ... ;

(* Monte Carlo Simulation *)
For[i = 0, i< Nstps, i++, x = RandomInteger[{1,Nspns}]; u = RandomReal[]; AppendTo[Savg, N[Total[S0]/Nspns]];Snew = S0; Snew[[x]] = Snew[[x]]*(-1);
 If[u≤BoltzRatio[Snew,S0], S0 = Snew,S0 =S0 ]];

(* Plots the average spin of the system as a function of steps*)
ListPlot[Savg]

(* Selects final 1000 elements of Savg and computes the average *)
N[Mean[ Part[Savg, Nstps-1000;;Nstps]]]

(*Calculates theoretical value of Savg based on equilibrium statistical physics*)
Savgtheory[mu_, H_, kBT_] := ...;
Savgtheory[mu, H, kBT]

(c) High Temperature Spin Simulations

(d)

(e)