Package com.imsl.test.example.math
Class ConjugateGradientEx2
java.lang.Object
com.imsl.test.example.math.ConjugateGradientEx2
- All Implemented Interfaces:
ConjugateGradient.Function,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.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidamultp(double[] p, double[] z) A user-supplied function which computes z=Ap.static voidvoidpreconditioner(double[] r, double[] z) Used to compute \(z = M^{-1}r \) where M is the preconditioning matrix and r and z are arrays of lengthn, the order of matrix M.
-
Constructor Details
-
ConjugateGradientEx2
- Throws:
SparseCholesky.NotSPDException
-
-
Method Details
-
amultp
public void amultp(double[] p, double[] z) Description copied from interface:ConjugateGradient.FunctionA user-supplied function which computes z=Ap.- Specified by:
amultpin interfaceConjugateGradient.Function- Parameters:
p- an inputdoublevector of length dimension of A.z- an outputdoublevector containing the matrix-vector product Ap.
-
preconditioner
public void preconditioner(double[] r, double[] z) Description copied from interface:ConjugateGradient.PreconditionerUsed to compute \(z = M^{-1}r \) where M is the preconditioning matrix and r and z are arrays of lengthn, the order of matrix M.- Specified by:
preconditionerin interfaceConjugateGradient.Preconditioner- Parameters:
r- an inputdoublearray of lengthngenerated during the implementation of thesolvemethod.z- an outputdoublearray of lengthn.
-
main
- Throws:
Exception
-