LINBCG is based on the routine linbcg described in section 2.7 of Numerical Recipes in C: The Art of Scientific Computing (Second Edition), published by Cambridge University Press, and is used by permission.
Note: Numerical Recipes recommends using double-precision arithmetic to perform this computation.
; Begin with an array A:
A = [[ 5.0, 0.0, 0.0, 1.0, -2.0], $
[ 3.0, -2.0, 0.0, 1.0, 0.0], $
[ 4.0, -1.0, 0.0, 2.0, 0.0], $
[ 0.0, 3.0, 3.0, 1.0 , 0.0], $
[-2.0, 0.0, 0.0, -1.0, 2.0]]
; Define a right-hand side vector B:
B = [7.0, 1.0, 3.0, 3.0, -4.0]
; Start with an initial guess at the solution:
X = REPLICATE(1.0, N_ELEMENTS(B))
; Solve the linear system Ax=b:
1.00000 1.00000 8.94134e-008 -2.37107e-007 -1.00000
The exact solution is [1, 1, 0, 0, -1].
The result is an n-element vector.
A row-indexed sparse array created by the SPRSIN function.
Note: If LINBCG is complex then only the real part is used for the computation.
An n-element vector containing the right-hand side of the linear system Ax=b.
An n-element vector containing the initial solution of the linear system.
Set this keyword to force the computation to be done in double-precision arithmetic.
Use this keyword to specify which convergence test should be used. Set ITOL to one of the following:
- Iteration stops when | A • x - b|/ |b| is less than the value specified by TOL.
- Iteration stops when |Ã-1• (A • x - b)|/|Ã-1 • b| (where Ã is a “preconditioning” matrix close to A) is less than the value specified by TOL.
- The routine uses its own estimate of error in x. Iteration stops when the magnitude of the error divided by the magnitude of x is less than the value specified by TOL. This is the default setting.
- The same as 3, except that the routine uses the largest (in absolute value) component of the error and the largest component of x rather than the vector magnitudes.
Use this keyword to specify the desired convergence tolerance. For single-precision calculations, the default value is 1.0 ∞ 10-7. For double-precision values, the default is 1.0 ∞ 10-14.
Use this keyword to specify an output variable that will be set to the number of iterations performed.
The maximum allowed number of iterations. The default is n2.
This page has no comments yet. Be the first one!