">

Metropolis.java


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

/*************************************************************************
 *  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);
      State state = new State(N, 0.5);
      while (true) {
         state.phase(kT);
         state.draw();
         StdDraw.show(50);
      }
   }
}

Copyright © 2006, Robert Sedgewick and Kevin Wayne.
Last updated: Wed Jul 19 14:22:24 EDT 2006.