/* From: "A SURVEY OF COMPUTATIONAL PHYSICS" by RH Landau, MJ Paez, and CC BORDEIANU Copyright Princeton University Press, Princeton, 2008. Electronic Materials copyright: R Landau, Oregon State Univ, 2008; MJ Paez, Univ Antioquia, 2008; and CC BORDEIANU, Univ Bucharest, 2008. 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