Below is the syntax highlighted version of Lorenz.java
from §1.5 Input and Output.
/****************************************************************************** * Compilation: javac Lorenz.java * Execution: java Lorenz * Dependencies: StdDraw.java * * Plot phase space (x vs. z) of Lorenz attractor with give set * of initial conditions. Uses Euler's method to numerically * approximate the answer. * ******************************************************************************/ public class Lorenz { public static double dx(double x, double y, double z) { return -10*(x - y); } public static double dy(double x, double y, double z) { return -x*z + 28*x - y; } public static double dz(double x, double y, double z) { return x*y - 8*z/3; } public static void main(String[] args) { double x = 0.0, y = 20.0, z = 25.0; double dt = 0.001; StdDraw.clear(StdDraw.LIGHT_GRAY); StdDraw.setXscale(-25, 25); StdDraw.setXscale(0, 50); StdDraw.enableDoubleBuffering(); // Use Euler's method to numerically solve ODE for (int i = 0; i < 50000; i++) { // update using Euler's method double xnew = x + dx(x, y, z) * dt; double ynew = y + dy(x, y, z) * dt; double znew = z + dz(x, y, z) * dt; x = xnew; y = ynew; z = znew; // draw StdDraw.setPenColor(StdDraw.BLUE); StdDraw.point(x, z); if (i % 10 == 0) { StdDraw.show(); StdDraw.pause(10); } } } }