MATLAB Function Reference
  Go to function:
    Search    Help Desk 
cgs    Examples   See Also

Conjugate Gradients Squared method

Syntax

Description

x = cgs(A,b) attempts to solve the system of linear equations A*x = b for x. The coefficient matrix A must be square and the right hand side (column) vector b must have length n, where A is n-by-n. cgs will start iterating from an initial estimate that by default is an all zero vector of length n. Iterates are produced until the method either converges, fails, or has computed the maximum number of iterations. Convergence is achieved when an iterate x has relative residual norm(b-A*x)/norm(b) less than or equal to the tolerance of the method. The default tolerance is 1e-6. The default maximum number of iterations is the minimum of n and 20. No preconditioning is used.

cgs(A,b,tol) specifies the tolerance of the method, tol.

cgs(A,b,tol,maxit) additionally specifies the maximum number of iterations, maxit.

cgs(A,b,tol,maxit,M) and cgs(A,b,tol,maxit,M1,M2) use left preconditioner M or M = M1*M2 and effectively solve the system inv(M)*A*x = inv(M)*b for x. If M1 or M2 is given as the empty matrix ([]), it is considered to be the identity matrix, equivalent to no preconditioning at all. Since systems of equations of the form M*y = r are solved using backslash within cgs, it is wise to factor preconditioners into their LU factors first. For example, replace cgs(A,b,tol,maxit,M) with:

cgs(A,b,tol,maxit,M1,M2,x0) specifies the initial estimate x0. If x0 is given as the empty matrix ([]), the default all zero vector is used.

x = cgs(A,b,tol,maxit,M1,M2,x0) returns a solution x. If cgs converged, a message to that effect is displayed. If cgs failed to converge after the maximum number of iterations or halted for any reason, a warning message is printed displaying the relative residual norm(b-A*x)/norm(b) and the iteration number at which the method stopped or failed.

[x,flag] = cgs(A,b,tol,maxit,M1,M2,x0) returns a solution x and a flag that describes the convergence of cgs:

Flag
Convergence
0
cgs converged to the desired tolerance tol within maxit iterations without failing for any reason.
1
cgs iterated maxit times but did not converge.
2
One of the systems of equations of the form M*y = r involving the preconditioner was ill-conditioned and did not return a useable result when solved by \ (backslash).
3
The method stagnated. (Two consecutive iterates were the same.)
4
One of the scalar quantities calculated during cgs became too small or too large to continue computing.

Whenever flag is not 0, the solution x returned is that with minimal norm residual computed over all the iterations. No messages are displayed if the flag output is specified.

[x,flag,relres] = cgs(A,b,tol,maxit,M1,M2,x0) also returns the relative residual norm(b-A*x)/norm(b). If flag is 0, then relres tol.

[x,flag,relres,iter] = cgs(A,b,tol,maxit,M1,M2,x0) also returns the iteration number at which x was computed. This always satisfies
0
iter maxit.

[x,flag,relres,iter,resvec] = cgs(A,b,tol,maxit,M1,M2,x0) also returns a vector of the residual norms at each iteration, starting from
resvec(1) = norm(b-A*x0). If flag is 0, resvec is of length iter+1 and resvec(end) tol*norm(b).

Examples

flag is 1 since cgs will not converge to the default tolerance 1e-6 within the default 20 iterations.

flag1 is 2 since the upper triangular U1 has a zero on its diagonal so cgs fails in the first iteration when it tries to solve a system such as U1*y = r for y with backslash.

flag2 is 0 since cgs will converge to the tolerance of 7.9e-16 (the value of relres2) at the fifth iteration (the value of iter2) when preconditioned by the incomplete LU factorization with a drop tolerance of 1e-6. resvec2(1) = norm(b) and resvec2(6) = norm(b-A*x2). You may follow the progress of cgs by plotting the relative residuals at each iteration starting from the initial estimate (iterate number 0) with semilogy(0:iter2,res2/norm(b),'-o').


See Also

bicg        BiConjugate Gradients method

bicgstab    BiConjugate Gradients Stabilized method

gmres       Generalized Minimum Residual method (with restarts)

luinc       Incomplete LU matrix factorizations

pcg         Preconditioned Conjugate Gradients method

qmr         Quasi-Minimal Residual method

\       Matrix left division

References

Sonneveld, Peter, CGS: A fast Lanczos-type solver for nonsymmetric linear systems, SIAM J. Sci. Stat. Comput., January 1989, Vol. 10, No. 1, pp. 36-52

Templates for the Solution of Linear Systems: Building Blocks for Iterative Methods, SIAM, Philadelphia, 1994.



[ Previous | Help Desk | Next ]