12.07.2015 Views

COPYRIGHT 2008, PRINCETON UNIVERSITY PRESS

COPYRIGHT 2008, PRINCETON UNIVERSITY PRESS

COPYRIGHT 2008, PRINCETON UNIVERSITY PRESS

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

398 chapter 15✞// Ising . java : 1−D Ising model with Metropolis algorithmimport java . io .∗ ; // Location of PrintWriterimport java . util .∗ ; // Location of Random☎public class Ising {public static int N = 1000; / / Number of atomspublic static double B = 1. , mu = .33 , J = .20 , k = 1. , T = 100000000.;public static void main ( String [] argv ) throws IOException , FileNotFoundException {Random randnum = new Random(500767) ; / / Seed random generatorPrintWriter q = new PrintWriter (new FileOutputStream ("ising .dat"), false );int i , j , M = 5000; / / Number of spin flipsdouble [] state = new double [N] ; double [] test = state ;double ES = energy ( state ) , p, ET; // State , test ’s energyfor ( i=0 ; i < N ; i++ ) state [ i ] = −1.; // Set initial statefor ( j=1 ; j = randnum . nextDouble () ) { state = test ; ES = ET; } // Test trialq. println (ES) ; / / Output energy to file}q. close () ;public static double energy ( double [] S) { // Method to calc energydouble FirstTerm = 0. , SecondTerm = 0. ;int i; / / Sum of energyfor ( i=0 ; i

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!