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

Generalized Minimum Residual method (with restarts)

Syntax

Description

x = gmres(A,b,restart) 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. 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 form
M*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:

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 residual
norm(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
Convergence
0
gmres converged to the desired tolerance tol within maxit iterations without failing for any reason.
1
gmres 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.)

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] = 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
relres tol.

[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).

Examples

flag is 1 since gmres(5) will not converge to the default tolerance 1e-6 within the default 10 outer iterations.

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.

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.


See Also

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

References

Saad, Youcef and Martin H. Schultz, GMRES: A generalized minimal residual algorithm for solving nonsymmetric linear systems, SIAM J. Sci. Stat. Comput., July 1986, Vol. 7, No. 3, pp. 856-869

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



[ Previous | Help Desk | Next ]