Solve system of linear equations — generalized minimum residual method

attempts to solve the system of linear equations `x`

= gmres(`A`

,`b`

)`A*x = b`

for
`x`

using the Generalized Minimum Residual Method. When the attempt is
successful, `gmres`

displays a message to confirm convergence. If
`gmres`

fails to converge after the maximum number of iterations or
halts for any reason, it displays a diagnostic message that includes the relative residual
`norm(b-A*x)/norm(b)`

and the iteration number at which the method
stopped. For this syntax, `gmres`

does not restart; the maximum number of
iterations is `min(size(A,1),10)`

.

restarts the method every `x`

= gmres(`A`

,`b`

,`restart`

)`restart`

inner iterations.
The maximum number of outer iterations is ```
outer =
min(size(A,1)/restart,10)
```

. The maximum number of total iterations is
`restart*outer`

, since `gmres`

performs
`restart`

inner iterations for each outer iteration. If
`restart`

is `size(A,1)`

or `[]`

, then
`gmres`

does not restart and the maximum number of total iterations is
`min(size(A,1),10)`

.

specifies the maximum number of outer iterations
such that the total number of iterations does not exceed `x`

= gmres(`A`

,`b`

,`restart`

,`tol`

,`maxit`

)`restart*maxit`

.
If `maxit`

is `[]`

then `gmres`

uses the
default, `min(size(A,1)/restart,10)`

. If `restart`

is
`size(A,1)`

or `[]`

, then the maximum number of total
iterations is `maxit`

(instead of `restart*maxit`

).
`gmres`

displays a diagnostic message if it fails to converge within
the maximum number of total iterations.

`[`

returns a flag that specifies whether the algorithm successfully converged. When
`x`

,`flag`

] = gmres(___)`flag = 0`

, convergence was successful. You can use this output syntax
with any of the previous input argument combinations. When you specify the
`flag`

output, `gmres`

does not display any diagnostic
messages.

Convergence of most iterative methods depends on the condition number of the coefficient matrix,

`cond(A)`

. You can use`equilibrate`

to improve the condition number of`A`

, and on its own this makes it easier for most iterative solvers to converge. However, using`equilibrate`

also leads to better quality preconditioner matrices when you subsequently factor the equilibrated matrix`B = R*P*A*C`

.You can use matrix reordering functions such as

`dissect`

and`symrcm`

to permute the rows and columns of the coefficient matrix and minimize the number of nonzeros when the coefficient matrix is factored to generate a preconditioner. This can reduce the memory and time required to subsequently solve the preconditioned linear system.

[1] Barrett, R., M. Berry, T. F. Chan,
et al., *Templates for the Solution of Linear Systems: Building Blocks for Iterative
Methods*, SIAM, Philadelphia, 1994.

[2] Saad, Yousef 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.