Metropolis.java


Below is the syntax highlighted version of Metropolis.java from §9.8 Data Analysis.


/******************************************************************************
 *  Compilation:  javac Metropolis.java
 *  Execution:    java Metropolis N kT
 *  
 *  Create an N-by-N grid of sites. Initially each is up with
 *  probability 1/2 and down with probability 1/2. 
 *  Run Metropolis iterations, and plot results after each phase.
 *
 *  
 *
 *  % java Metropolis 64 2
 *
 ******************************************************************************/

public class Metropolis {
    public static void main(String[] args) {
        int N = Integer.parseInt(args[0]);
        double kT = Double.parseDouble(args[1]);
        StdDraw.setXscale(0, N);
        StdDraw.setYscale(0, N);
        StdDraw.enableDoubleBuffering();
        State state = new State(N, 0.5);
        while (true) {
            state.phase(kT);
            state.draw();
            StdDraw.show();
            StdDraw.pause(50);
        }
    }
}


Copyright © 2000–2017, Robert Sedgewick and Kevin Wayne.
Last updated: Fri Oct 20 14:12:12 EDT 2017.