JamaTest.java


Below is the syntax highlighted version of JamaTest.java from §9.5 Numerical Solutions to Differential Equations.


/******************************************************************************
 *  Compilation:  javac -classpath .:jama.jar JamaTest.java
 *  Execution:    java  -classpath .:jama.jar JamaTest
 *  
 *  Test client that uses the JAMA linear algebra library.
 *  
 *       http://math.nist.gov/javanumerics/jama/
 *
 *  Note: to use the Jama package, you need to have the library jama.jar
 *  in the current working directory.
 *
 *  It can be downloaded from either
 *
 *     http://www.cs.princeton.edu/IntroCS/95linear/jama.jar
 *     http://math.nist.gov/javanumerics/jama/Jama-1.0.1.jar
 *
 ******************************************************************************/

import Jama.Matrix; 

public class JamaTest {
   public static void main(String[] args) { 
      Matrix A = new Matrix(new double[][] { { 0,  1,  1 },
                                             { 2,  4, -2 },
                                             { 0,  3, 15 } }); 

      Matrix b = new Matrix(new double[][] { {  4 },
                                             {  2 },
                                             { 36 } });
      Matrix x = A.solve(b);
      Matrix residual = A.times(x).minus(b);
      double rnorm = residual.normInf();

      StdOut.println("A");
      A.print(9, 6);                // printf("%9.6f");

      StdOut.println("b");
      b.print(9, 6);

      StdOut.println("x");
      x.print(9, 6);
      StdOut.println(x);

      StdOut.println("residual");
      residual.print(9, 6);

   }

}


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