MATLAB Function Reference | Search  Help Desk |
gmres | Examples See Also |
Generalized Minimum Residual method (with restarts)
x = gmres(A,b,restart) gmres(A,b,restart,tol) gmres(A,b,restart,tol,maxit) gmres(A,b,restart,tol,maxit,M) gmres(A,b,restart,tol,maxit,M1,M2) gmres(A,b,restart,tol,maxit,M1,M2,x0) x = gmres(A,b,restart,tol,maxit,M1,M2,x0) [x,flag] = gmres(A,b,restart,tol,maxit,M1,M2,x0) [x,flag,relres] = gmres(A,b,restart,tol,maxit,M1,M2,x0) [x,flag,relres,iter] = gmres(A,b,restart,tol,maxit,M1,M2,x0) [x,flag,relres,iter,resvec] = gmres(A,b,restart,tol,maxit,M1,M2,x0)
x = gmres(A,b,restart)
attempts to solve the system of linear equationsA*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
. gmres
will start iterating from an initial estimate that by default is an all zero vector of length n
. gmres
will restart itself every restart iterations using the last iterate from the previous outer iteration as the initial guess for the next outer iteration. 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/restart
and 10. No preconditioning is used.
gmres(A,b,restart,tol)
specifies the tolerance of the method, tol
.
gmres(A,b,restart,tol,maxit)
additionally specifies the maximum number of iterations, maxit
.
gmres(A,b,restart,tol,maxit,M) and
gmres(A,b,restart,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 formM*y = r
are solved using backslash within gmres, it is wise to factor preconditioners into their LU factors first. For example, replace gmres(A,b,restart,tol,maxit,M)
with:
[M1,M2] = lu(M);
gmres(A,b,restart,tol,maxit,M1,M2).
gmres(A,b,restart,tol,maxit,M1,M2,x0)
specifies the first initial estimate x0
. If x0
is given as the empty matrix ([]
), the default all zero vector is used.
x = gmres(A,b,restart,tol,maxit,M1,M2,x0)
returns a solution x
. If gmres
converged, a message to that effect is displayed. If gmres
failed to converge after the maximum number of iterations or halted for any reason, a warning message is printed displaying the relative residualnorm(b-A*x)/norm(b)
and the iteration number at which the method stopped or failed.
[x,flag] = gmres(A,b,restart,tol,maxit,M1,M2,x0)
returns a solution x
and a flag which describes the convergence of gmres
: 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] = gmres(A,b,restart,tol,maxit,M1,M2,x0)
also returns the relative residual norm(b-A*x)/norm(b)
. If flag
is 0
, then [x,flag,relres,iter] = gmres(A,b,restart,tol,maxit,M1,M2,x0)
also returns both the outer and inner iteration numbers at which x
was computed. The outer iteration number iter(1)
is an integer between 0 and maxit
. The inner iteration number iter(2)
is an integer between 0
and restart
.
[x,flag,relres,iter,resvec] =
gmres(A,b,restart,tol,maxit,M1,M2,x0)
also returns a vector of the residual norms at each inner iteration, starting from resvec(1) = norm(b-A*x0)
. If flag
is 0
and iter = [i j]
, resvec
is of length (i-1)*restart+j+1
and resvec(end)
tol*norm(b)
.
load west0479 A = west0479 b = sum(A,2) [x,flag] = gmres(A,b,5)
flag
is 1
since gmres(5)
will not converge to the default tolerance 1e-6
within the default 10 outer iterations.
[L1,U1] = luinc(A,1e-5); [x1,flag1] = gmres(A,b,5,1e-6,5,L1,U1);
flag1
is 2
since the upper triangular U1
has a zero on its diagonal so gmres(5)
fails in the first iteration when it tries to solve a system such as U1*y = r
for y
with backslash.
[L2,U2] = luinc(A,1e-6); tol = 1e-15; [x4,flag4,relres4,iter4,resvec4] = gmres(A,b,4,tol,5,L2,U2); [x6,flag6,relres6,iter6,resvec6] = gmres(A,b,6,tol,3,L2,U2); [x8,flag8,relres8,iter8,resvec8] = gmres(A,b,8,tol,3,L2,U2);
flag4
, flag6
, and flag8
are all 0
since gmres
converged when restarted at iterations 4, 6, and 8 while preconditioned by the incomplete LU factorization with a drop tolerance of 1e-6
. This is verified by the plots of outer iteration number against relative residual. A combined plot of all three clearly shows the restarting at iterations 4 and 6. The total number of iterations computed may be more for lower values of restart
, but the number of length n
vectors stored is fewer, and the amount of work done in the method decreases proportionally.bicg
BiConjugate Gradients method
bicgstab
BiConjugate Gradients Stabilized method
cgs
Conjugate Gradients Squared method
luinc
Incomplete LU matrix factorizations
pcg
Preconditioned Conjugate Gradients method
qmr
Quasi-Minimal Residual method
\
Matrix left division