Solve A x = b
using the Preconditioned GMRES iterative method with
restart, a.k.a. PGMRES(m).
min (10, numel (b) / restart)
is used.
zeros (size (b))
is used.
numel (b)
is used.
Argument A can be passed as a matrix, function handle, or inline
function f
such that f(x) = A*x
.
The preconditioner P is given as P = M1 * M2
. Both M1
and M2 can be passed as a matrix, function handle, or inline function
g
such that g(x) = M1\x
or g(x) = M2\x
.
Besides the vector x, additional outputs are:
See also: bicg, bicgstab, cgs, pcg, pcr, qmr.
The following code
dim = 20; A = spdiags ([-ones(dim,1) 2*ones(dim,1) ones(dim,1)], [-1:1], dim, dim); b = ones (dim, 1); [x, flag, relres, iter, resvec] = gmres (A, b, 10, 1e-10, dim, @(x) x ./ diag (A), [], b)
Produces the following output
x = 0.29289 0.41421 0.46447 0.48528 0.49390 0.49748 0.49895 0.49957 0.49981 0.49996 0.49989 0.50017 0.49956 0.50104 0.49747 0.50610 0.48528 0.53553 0.41421 0.70711 flag = 0 relres = 4.6820e-11 iter = 2 6 resvec = 2.3452e+00 4.8901e-01 2.3940e-01 9.3557e-02 3.8321e-02 1.6493e-02 6.4668e-03 2.8384e-03 1.0969e-03 4.8636e-04 1.8564e-04 1.0114e-04 4.1088e-05 1.7538e-05 6.9496e-06 3.0391e-06 1.1659e-06 5.2776e-07 1.8936e-07 9.2733e-08 2.2371e-08 8.0061e-09 3.7557e-09 1.4040e-09 6.2002e-10 2.4414e-10 1.0469e-10
Package: octave