MATLAB Function Reference | Search  Help Desk |
qmr | Examples See Also |
x = qmr(A,b) qmr(A,b,tol) qmr(A,b,tol,maxit) qmr(A,b,tol,maxit,M1) qmr(A,b,tol,maxit,M1,M2) qmr(A,b,tol,maxit,M1,M2,x0) x = qmr(A,b,tol,maxit,M1,M2,x0) [x,flag] = qmr(A,b,tol,maxit,M1,M2,x0) [x,flag,relres] = qmr(A,b,tol,maxit,M1,M2,x0) [x,flag,relres,iter] = qmr(A,b,tol,maxit,M1,M2,x0) [x,flag,relres,iter,resvec] = qmr(A,b,tol,maxit,M1,M2,x0)
x = qmr(A,b)
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
. qmr
will start iterating from an initial estimate that by default is an all zero vector of length n
. 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
and 20. No preconditioning is used.
qmr(A,b,tol)
specifies the tolerance of the method, tol
.
qmr(A,b,tol,maxit)
additionally specifies the maximum number of iterations, maxit
.
qmr(A,b,tol,maxit,M1) and qmr(A,b,tol,maxit,M1,M2)
use left and right preconditioners M1
and M2
and effectively solve the system inv(M1)*A*inv(M2)*y = inv(M1)*b
for y
, where x = inv(M2)*y
. 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 M1*y = r
are solved using backslash within qmr
, it is wise to factor preconditioners into their LU factorizations first. For example, replace qmr(A,b,tol,maxit,M,[]) or qmr(A,b,tol,maxit,[],M) with:
[M1,M2] = lu(M); qmr(A,b,tol,maxit,M1,M2).
qmr(A,b,tol,maxit,M1,M2,x0)
specifies the initial estimate x0
. If x0
is given as the empty matrix ([]
), the default all zero vector is used.
x = qmr(A,b,tol,maxit,M1,M2,x0)
returns a solution x
. If qmr
converged, a message to that effect is displayed. If qmr
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] = qmr(A,b,tol,maxit,M1,M2,x0)
returns a solution x
and a flag which describes the convergence of qmr
: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] = qmr(A,b,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] = qmr(A,b,tol,maxit,M1,M2,x0)
also returns the iteration number at which x
was computed. This always satisfies0
iter
maxit
.
[x,flag,relres,iter,resvec] = qmr(A,b,tol,maxit,M1,M2,x0)
also returns a vector of the residual norms at each iteration, starting from resvec(1) = norm(b-A*x0)
. If flag
is 0
, resvec
is of length iter+1
and resvec(end)
tol*norm(b)
.
load west0479 A = west0479 b = sum(A,2) [x,flag] = qmr(A,b)
flag
is 1
since qmr
will not converge to the default tolerance 1e-6
within the default 20 iterations.
[L1,U1] = luinc(A,1e-5) [x1,flag1] = qmr(A,b,1e-6,20,L1,U1)
flag1
is 2
since the upper triangular U1
has a zero on its diagonal so qmr 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) [x2,flag2,relres2,iter2,resvec2] = qmr(A,b,1e-15,10,L2,U2)
flag2
is 0
since qmr will converge to the tolerance of 1.9e-16
(the value of relres2
) at the eighth iteration (the value of iter2
) when preconditioned by the incomplete LU factorization with a drop tolerance of 1e-6
. resvec2(1) = norm(b)
and resvec2(9) = norm(b-A*x2)
. You may follow the progress of qmr by plotting the relative residuals at each iteration starting from the initial estimate (iterate number 0) with semilogy(0:iter2,resvec2/norm(b),'-o')
.bicg
BiConjugate Gradients method
bicgstab
BiConjugate Gradients Stabilized method
cgs
Conjugate Gradients Squared method
gmres
Generalized Minimum Residual method (with restarts)
luinc
Incomplete LU matrix factorizations
pcg
Preconditioned Conjugate Gradients method
\
Matrix left division