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

BiConjugate Gradients method

Syntax

Description

x = bicg(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. bicg 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.

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

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

bicg(A,b,tol,maxit,M) and bicg(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 bicg, it is wise to factor preconditioners into their LU factors first. For example, replace bicg(A,b,tol,maxit,M) with:

bicg(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 = bicg(A,b,tol,maxit,M1,M2,x0) returns a solution x. If bicg converged, a message to that effect is displayed. If bicg 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] = bicg(A,b,tol,maxit,M1,M2,x0) returns a solution x and a flag that describes the convergence of bicg:

Flag
Convergence
0
bicg converged to the desired tolerance tol within maxit iterations without failing for any reason.
1
bicg 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 bicg 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] = bicg(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] = bicg(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] = bicg(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

Start with A = west0479 and make the true solution the vector of all ones.

We could accurately solve A*x = b using backslash since A is not so large.

Now try to solve A*x = b with bicg.

The value of flag indicates that bicg iterated the default 20 times without converging. The value of iter shows that the method behaved so badly that the initial all zero guess was better than all the subsequent iterates. The value of relres supports this: relres = norm(b-A*x)/norm(b) = norm(b)/norm(b) = 1. The plot semilogy(0:20,resvec/norm(b),'-o') below confirms that the unpreconditioned method oscillated rather wildly.


Try an incomplete LU factorization with a drop tolerance of 1e-5 for the preconditioner.

A warning message indicates a zero on the main diagonal of the upper triangular U1. Thus it is singular. When we try to use it as a preconditioner:

the method fails in the very first iteration when it tries to solve a system of equations involving the singular U1 with backslash. It is forced to return the initial estimate since no other iterates were produced.

Try again with a slightly less sparse preconditioner:

This time there is no warning message. All entries on the main diagonal of U2 are nonzero

and bicg converges to within the desired tolerance at iteration number 8. Decreasing the value of the drop tolerance increases the fill-in of the incomplete factors but also increases the accuracy of the approximation to the original matrix. Thus, the preconditioned system becomes closer to inv(U)*inv(L)*L*U*x = inv(U)*inv(L)*b, where L and U are the true LU factors, and closer to being solved within a single iteration.

The next graph shows the progress of bicg using six different incomplete LU factors as preconditioners. Each line in the graph is labelled with the drop tolerance of the preconditioner used in bicg.


This does not give us any idea of the time involved in creating the incomplete factors and then computing the solution. The following graph plots drop tolerance of the incomplete LU factors against the time to compute the preconditioner, the time to iterate once the preconditioner has been computed, and their sum, the total time to solve the problem. The time to produce the factors does not increase very quickly with the fill-in, but it does slow down the average time for an iteration. Since fewer iterations are performed, the total time to solve the problem decreases. west0479 is quite a small matrix, only 139-by-139, and preconditioned bicg still takes longer than backslash.


See Also

bicgstab    BiConjugate Gradients Stabilized method

cgs         Conjugate Gradients Squared 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

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



[ Previous | Help Desk | Next ]