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.Constructor and Description |
---|
ConjugateGradientEx2(int n,
int c) |
Modifier and Type | Method and 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. |
public ConjugateGradientEx2(int n, int c) throws SparseCholesky.NotSPDException
SparseCholesky.NotSPDException
public void amultp(double[] p, double[] z)
ConjugateGradient.Function
amultp
in interface ConjugateGradient.Function
p
- an input double
vector of length
dimension of A.z
- an output double
vector containing the
matrix-vector product Ap.public void preconditioner(double[] r, double[] z)
ConjugateGradient.Preconditioner
n
,
the order of matrix M.preconditioner
in interface ConjugateGradient.Preconditioner
r
- an input double
array of length n
generated during the implementation of the solve
method.z
- an output double
array of length n
.Copyright © 2020 Rogue Wave Software. All rights reserved.