MATLAB Function Reference | Search  Help Desk |
bicg | Examples See Also |
x = bicg(A,b) bicg(A,b,tol) bicg(A,b,tol,maxit) bicg(A,b,tol,maxit,M) bicg(A,b,tol,maxit,M1,M2) bicg(A,b,tol,maxit,M1,M2,x0) x = bicg(A,b,tol,maxit,M1,M2,x0) [x,flag] = bicg(A,b,tol,maxit,M1,M2,x0) [x,flag,relres] = bicg(A,b,tol,maxit,M1,M2,x0) [x,flag,relres,iter] = bicg(A,b,tol,maxit,M1,M2,x0) [x,flag,relres,iter,resvec] = bicg(A,b,tol,maxit,M1,M2,x0)
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:
[M1,M2] = lu(M); bicg(A,b,tol,maxit,M1,M2).
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
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 esvec(1) = norm(b-A*x0)
. If flag
is 0
, resvec
is of length iter+1
and resvec(end)
tol*norm(b)
.
Start with A = west0479
and make the true solution the vector of all ones.
load west0479 A = west0479 b = sum(A,2)We could accurately solve
A*x = b
using backslash since A
is not so large.
x = A \ b norm(b-A*x) / norm(b) = 6.8476e-18Now try to solve
A*x = b
with bicg
.
[x,flag,relres,iter,resvec] = bicg(A,b) flag = 1 relres = 1 iter = 0The 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.1e-5
for the preconditioner.
[L1,U1] = luinc(A,1e-5) nnz(A) = 1887 nnz(L1) = 5562 nnz(U1) = 4320A 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:
[x,flag,relres,iter,resvec] = bicg(A,b,1e-6,20,L1,U1) flag = 2 relres = 1 iter = 0 resvec = 7.0557e+005the 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:
[L2,U2] = luinc(A,1e-6) nnz(L2) = 6231 nnz(U2) = 4559This time there is no warning message. All entries on the main diagonal of
U2
are nonzero
[x,flag,relres,iter,resvec] = bicg(A,b,1e-15,10,L2,U2) flag = 0 relres = 2.8664e-16 iter = 8and
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
.west0479
is quite a small matrix, only 139-by-139, and preconditioned bicg
still takes longer than backslash.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