The GS_ITER function solves an n by n linear system of equations using Gauss-Seidel iteration with over- and under-relaxation to enhance convergence.
| Note |
This routine is written in the IDL language. Its source code can be found in the file gs_iter.pro in the lib subdirectory of the IDL distribution.
Result = GS_ITER( A, B [, /CHECK] [, /DOUBLE] [, LAMBDA=value{0.0 to 2.0}] [, MAX_ITER=value] [, TOL=value] [, X_0=vector] )
Returns the solution to the linear system of equations of the specified dimensions.
An n by n integer, single-, or double-precision floating-point array. On output, A is divided by its diagonal elements. Integer input values are converted to single-precision floating-point values.
A vector containing the right-hand side of the linear system Ax=b. On output, B is divided by the diagonal elements of A.
Set this keyword to check the array A for diagonal dominance. If A is not in diagonally dominant form, GS_ITER reports the fact but continues processing on the chance that the algorithm may converge.
Set this keyword to force the computation to be done in double-precision arithmetic.
A scalar value in the range: [0.0, 2.0]. This value determines the amount of relaxation. Relaxation is a weighting technique used to enhance convergence.
The maximum allowed number of iterations. The default value is 30.
The relative error tolerance between current and past iterates calculated as: ½( (current-past)/current )½. The default is 1.0 ´ 10-4.
An n-element vector that provides the algorithm's starting point. The default is [1.0, 1.0, ... , 1.0].
; Define an array A: A = [[ 1.0, 7.0, -4.0], $ [ 4.0, -4.0, 9.0], $ [12.0, -1.0, 3.0]] ; Define the right-hand side vector B: B = [12.0, 2.0, -9.0] ; Compute the solution to the system: RESULT = GS_ITER(A, B, /CHECK)
IDL prints:
Input matrix is not in Diagonally Dominant form. Algorithm may not converge. % GS_ITER: Algorithm failed to converge within given parameters.
Since the A represents a system of linear equations, we can reorder it into diagonally dominant form by rearranging the rows:
A = [[12.0, -1.0, 3.0], $ [ 1.0, 7.0, -4.0], $ [ 4.0, -4.0, 9.0]] ; Make corresponding changes in the ordering of B: B = [-9.0, 12.0, 2.0] ; Compute the solution to the system: RESULT = GS_ITER(A, B, /CHECK)
IDL prints:
-0.999982 2.99988 1.99994
Introduced: Pre 4.0
CRAMER, LU_COMPLEX, CHOLSOL, LUSOL, SVSOL, TRISOL