/* * Laplace.java * An applet to compute the solution of a (built-in) 2nd order PDE. * The solution method is Jacobi iteration, and the partial solutions * are displayed as they are computed, until the errot tolerance is reached. */ import java.awt.*; import java.awt.event.*; public class Laplace extends java.applet.Applet implements Runnable // implements ActionListener { Thread thread; int R = 64; // number of rows in the solution matrix int C = 128; // number of columns double[][] phi0 = new double [R][C]; double[][] phi1 = new double [R][C]; // solution and initial matrices double tolerance = .001; // error tolerance int n = 10; // number of iterations between error computation // and displays of solution int npix; // number of pixels displayed per matrix element // in each direction int minz; // min value of solution in range for color map int maxz; // max value of solution in range Image buffer; // off screen buffer Graphics og; // off screen graphics public void init () { int i,j; //initialize initial matrix to 0 for (i=0; i tolerance ) { // phi0 has current solution, compute phi1 as new solution // after n iterations Jacobi(n); // compare phi0 and phi1 for error eps = 0.0; for (int i=1; i<(R-1); i++) for (int j=1; j<(C-1); j++) eps = Math.max(eps, Math.abs(phi1[i][j] - phi0[i][j])); // move phi1 to be new current solution phi0 for (int i=0; i