bicgstab

Solve a system of linear equations with the biconjugate gradient stabilized method.

Syntax

x = bicgstab(A,b)

x = bicgstab(A,b,rtol)

x = bicgstab(A,b,rtol,maxit)

x = bicgstab(A,b,rtol,maxit,M1)

x = bicgstab(A,b,rtol,maxit,M1,M2)

x = bicgstab(A,b,rtol,maxit,M1,M2,x0)

[x, iflag, relres, iter, resvec] = bicgstab(...)

Inputs

A
The left-hand side matrix, or a function name or handle to generate A*x.
b
The right-hand side vector.
Dimension: vector
rtol
The relative convergerce tolerance (default: 1.0e-6).
Type: double
Dimension: scalar
maxit
The maximum number of iterations (default: min(size(b, 1), 20)).
Type: integer
Dimension: scalar
M1
The left preconditioner matrix, or a function name or handle to generate M1\x. (default: none or [])
Dimension: matrix
M2
The right preconditioner matrix, or a function name or handle to generate M2\x. (default: none or [])
x0
The initial estimate of the solution (default: zeroes(length(b),1)).
Dimension: vector

Outputs

x
The solution vector.
iflag
The termination status.
iflag = 0:
The algorithm converged within the allowed tolerance and number of iterations.
iflag = 1:
The algorithm completed the allowed iterations without converging.
iflag = 2:
A preconditioner matrix was singular.
iflag = 3:
The algorithm converged, but not at a solution due to stagnation.
iflag = 4:
The algorithm stopped prematurely because it could not determine a descent direction.
relres
The magnitude of the residual relative to norm(b).
iter
The number of iterations performed. If convergence occurs half way through an iteration it is recorded as such.
resvec
The residual vector.

Example

Case using a function handle for A and a left preconditioner.

A = [3, 1, 0; 0, 5, 6; -2, 0, 4];
b = [13; 14; -10];
tol = 0.0001;
max_it = 5;
M1 = diag(diag(A));
M2 = [];
x0 = [];
Ahandle = @(x) A * x;
[x, iflag, relres, iter, resvec] = bicgstab(Ahandle, b, tol, max_it, M1, M2, x0)
x = [Matrix] 3 x 1
 3.00000
 4.00000
-1.00000
iflag = 0
relres = 1.30675106e-16
iter = 2.5
resvec = [Matrix] 6 x 1
2.15639e+01
2.10064e+01
6.74333e+00
1.84478e-01
1.35884e-01
2.81786e-15