/* Exhf.java Explicit heat flow equation, finite differenced. Adapted from Jon Claerbout's Imaging the Earth's Interior (1985), p. 94, by John N. Louie, 28 November 1998. */ /* Include the usual classes */ import java.util.*; import java.io.*; import java.lang.Math; /* Declare a class with a main() method to contain the finite-difference code. */ /* When you change the code in this file, make a copy to a new file with a new name like "ex6exhf.java", and be sure to make the same change to the class name below - e.g. "class ex6exhf" */ class exhf { /* The main() method compiles into a file named "exhf.class" that you run in the Java virtual machine as a stand-alone application with a command such as "java exhf"; or however you have renamed it. */ public static void main(String args[]) /* No runtime arguments needed */ { System.out.println("Starting exhf..."); /* Declare variables */ int nx, ia, it, ix; float alpha, q[], qp[]; /* Dimension arrays */ nx = 12; q = new float[nx]; qp = new float[nx]; /* Loop through a stable and an unstable case */ for (ia=0; ia<2; ia++) { alpha = 0.333F*(ia+1); System.out.println("alpha = " + alpha); /* Initial temperature is a step function in x */ for (ix=0; ix<6; ix++) q[ix] = 0F; for (ix=6; ix<12; ix++) q[ix] = 1F; /* Iterate in time */ for (it=0; it<6; it++) { /* Print current state of array */ for (ix=0; ix