Class ConjugateGradientEx2

java.lang.Object
com.imsl.test.example.math.ConjugateGradientEx2
All Implemented Interfaces:
ConjugateGradient.Function, ConjugateGradient.Preconditioner

public class ConjugateGradientEx2 extends Object implements ConjugateGradient.Preconditioner

Solves a sparse linear system using the conjugate gradient method with preconditioning.

In this example, two different preconditioners are used to find the solution of a sparse positive definite linear system. The system occurs in a finite difference solution of Laplace's equation on a regular \(c \times c\) grid, where we use \(c = 50\). The matrix is $$ A = E(c^2, c) $$. For the first solution, Jacobi preconditioning with preconditioner \(M={\rm{diag}}(A)\) is used. The required iteration number and maximum absolute error are printed. Next, a more complicated preconditioning matrix, consisting of the symmetric tridiagonal part of A, is used. Again, the iteration number and the maximum absolute error are printed. The iteration number is substantially reduced.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    ConjugateGradientEx2(int n, int c)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    amultp(double[] p, double[] z)
    A user-supplied function which computes z=Ap.
    static void
    main(String[] args)
     
    void
    preconditioner(double[] r, double[] z)
    Used to compute \(z = M^{-1}r \) where M is the preconditioning matrix and r and z are arrays of length n, the order of matrix M.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • amultp

      public void amultp(double[] p, double[] z)
      Description copied from interface: ConjugateGradient.Function
      A user-supplied function which computes z=Ap.
      Specified by:
      amultp in interface ConjugateGradient.Function
      Parameters:
      p - an input double vector of length dimension of A.
      z - an output double vector containing the matrix-vector product Ap.
    • preconditioner

      public void preconditioner(double[] r, double[] z)
      Description copied from interface: ConjugateGradient.Preconditioner
      Used to compute \(z = M^{-1}r \) where M is the preconditioning matrix and r and z are arrays of length n, the order of matrix M.
      Specified by:
      preconditioner in interface ConjugateGradient.Preconditioner
      Parameters:
      r - an input double array of length n generated during the implementation of the solve method.
      z - an output double array of length n.
    • main

      public static void main(String[] args) throws Exception
      Throws:
      Exception