/* From: "COMPUTATIONAL PHYSICS, 2nd Ed" by RH Landau, MJ Paez, and CC Bordeianu Copyright Wiley-VCH, 2007. Electronic Materials copyright: R Landau, Oregon State Univ, 2007; MJ Paez, Univ Antioquia, 2007; & CC Bordeianu, Univ Bucharest, 2007 Support by National Science Foundation */ // ising.c: ising model of magnetic dipole string // Plot without conneting datapoints with lines #include #include #include // if you don't have drand48 uncomment the following two lines #define drand48 1.0/RAND_MAX*rand #define srand48 srand #define max 100 // number of objects #define kt 100.0 // temperature #define J -1 // exchange energy #define seed 68111 // seed for srand48 main() { int i, j, element, array[max]; double olden, newen; double energy(int array[]); // energy of system FILE *output1, *output2; // save spin ups and output1= fopen("spin-up.dat" ,"w"); // downs in two files output2= fopen("spin-down.dat", "w"); srand48(seed); // seed generator // uniform start for (i = 0; iolden) && (exp((-newen + olden)/kt) <= drand48()) ) { array[element]= array[element]*(-1); } // save "map" of spins for (j = 0; j