Documentation

QMR.

Quasi-minimal residual method

Syntax

x = qmr(a,b)
QMR.(A,b,tol)
qmr(a,b,tol,maxit)
QMR.(A,b,tol,maxit,M)
QMR.(A,b,tol,maxit,M1,M2)
QMR(a,b,tol,maxit,m1,m2,x0)
[x,flag] = qmr(a,b,...)
[x,标志,relres] = qmr(a,b,...)
[x,标志,relres,iter] = qmr(a,b,...)
[x,flag,relres,iter,resvec] = qmr(A,b,...)

描述

x = qmr(a,b)attempts to solve the system of linear equations斧头=bforx。这n-经过-n系数矩阵Amust be square and should be large and sparse. The column vectorbmust have lengthn。You can specifyAas a function handle,好玩儿,这样的Afun(x,'notransp')returns斧头Afun(x,'transp')returnsA'*x

Parameterizing Functionsexplains how to provide additional parameters to the function好玩儿, as well as the preconditioner functionMFUN.described below, if necessary.

如果QMR.收敛,显示对该效果的消息。如果QMR.fails to converge after the maximum number of iterations or halts for any reason, a warning message is printed displaying the relative residual规范(B-A * x)/常规(b)和the iteration number at which the method stopped or failed.

QMR.(A,b,tol)指定方法的容差。如果[], thenQMR.uses the default,1e-6

qmr(a,b,tol,maxit)指定最大迭代次数。如果Maxit.[], thenQMR.uses the default,min(n,20)

QMR.(A,b,tol,maxit,M)QMR.(A,b,tol,maxit,M1,M2)使用预处理器M或者M = M1*M2和effectively solve the systeminv(m)* a * x = inv(m)* bforx。如果M[]thenQMR.applies no preconditioner.M可以是函数手柄MFUN.such thatmfun(x,'notransp')returnsM\xmfun(x,'transp')returnsM'\x

QMR(a,b,tol,maxit,m1,m2,x0)specifies the initial guess. Ifx0[], thenQMR.使用默认值,是全零向量。

[x,flag] = qmr(a,b,...)还返回收敛标志。

旗帜

收敛

0

QMR.converged to the desired tolerance之内Maxit.iterations.

1

QMR.迭代Maxit.times but did not converge.

2

PreconditionerMwas ill-conditioned.

3

这method stagnated. (Two consecutive iterates were the same.)

4

One of the scalar quantities calculated duringQMR.became too small or too large to continue computing.

Whenever旗帜不是0, 解决方案x返回的是,在所有迭代中都有最小的常态剩余计算。如果如果是,则不会显示任何消息旗帜输出已指定。

[x,标志,relres] = qmr(a,b,...)还返回相对残差规范(B-A * x)/常规(b)。如果旗帜0,Relres <= tol

[x,标志,relres,iter] = qmr(a,b,...)also returns the iteration number at whichx计算在哪里0 <= iter <= maxit

[x,flag,relres,iter,resvec] = qmr(A,b,...)还返回每次迭代的残余规范的向量,包括norm(b-A*x0)

例子

Using qmr with a Matrix Input

This example shows how to useQMR.with a matrix input. The code:

n = 100; on = ones(n,1); A = spdiags([-2*on 4*on -on],-1:1,n,n); b = sum(A,2); tol = 1e-8; maxit = 15; M1 = spdiags([on/(-2) on],-1:0,n,n); M2 = spdiags([4*on -on],0:1,n,n); x = qmr(A,b,tol,maxit,M1,M2);

displays the message:

QMR在迭代9中融合到一个解决方案......相对残差5.6E-009

使用QMR具有功能句柄

此示例替换矩阵A在前面的示例中,具有句柄到矩阵矢量产品功能好玩儿。该示例包含在文件中run_qmr

  • CallsQMR.with the function handle@afunas its first argument.

  • Contains好玩儿as a nested function, so that all variables inrun_qmr可供选择好玩儿

这following shows the code forrun_qmr:

function x1 = run_qmr n = 100; on = ones(n,1); A = spdiags([-2*on 4*on -on],-1:1,n,n); b = sum(A,2); tol = 1e-8; maxit = 15; M1 = spdiags([on/(-2) on],-1:0,n,n); M2 = spdiags([4*on -on],0:1,n,n); x1 = qmr(@afun,b,tol,maxit,M1,M2); function y = afun(x,transp_flag) if strcmp(transp_flag,'transp') % y = A'*x y = 4 * x; y(1:n-1) = y(1:n-1) - 2 * x(2:n); y(2:n) = y(2:n) - x(1:n-1); elseif strcmp(transp_flag,'notransp') % y = A*x y = 4 * x; y(2:n) = y(2:n) - 2 * x(1:n-1); y(1:n-1) = y(1:n-1) - x(2:n); end end end

When you enter

x1=run_qmr;

MATLAB®软件显示消息

QMR.converged at iteration 9 to a solution with relative residual 5.6e-009

Using qmr with a Preconditioner

此示例演示了使用预处理器。

加载A = west0479, a real 479-by-479 nonsymmetric sparse matrix.

loadWest0479.; A = west0479;

Definebso that the true solution is a vector of all ones.

B =完整(总和(a,2));

设置容差和最大迭代次数。

托= 1e-12; maxit = 20;

采用QMR.to find a solution at the requested tolerance and number of iterations.

[x0,fl0,rr0,it0,rv0] = qmr(a,b,tol,maxit);

fl0是1 becauseQMR.不收敛到所要求的容忍度1e-12在请求的20次迭代中。十七次迭代是最好的近似解,是如所示返回的解决方案it0 = 17。MATLAB stores the residual history inrv0

Plot the behavior ofQMR.

semilogy(0:maxit,rv0/norm(b),'-o');xlabel('迭代号');ylabel(“相对残差”);

绘图显示解决方案不收敛。您可以使用预处理程序来提高结果。

创建预处理器ilu, since the matrixA是nonsymmetric.

[L,U] = ilu(A,struct('类型','ilutp','droptol',1E-5));
Error using ilu There is a pivot equal to zero. Consider decreasing the drop tolerance or consider using the 'udiag' option.

Matlab无法构建不完整的LU,因为它会导致一个奇异的因素,这是一个作为预处理者的唯一因素。

您可以重新尝试减少跌落公差,如错误消息所示。

[L,U] = ilu(A,struct('类型','ilutp','droptol',1E-6));[X1,FL1,RR1,IT1,RV1] = QMR(A,B,TOL,MAXIT,L,U);

fl1是0 becauseQMR.drives the relative residual to4.1410E-014(the value ofRR1.). The relative residual is less than the prescribed tolerance of1e-12at the sixth iteration (the value ofit1) when preconditioned by the incomplete LU factorization with a drop tolerance of1e-6。输出RV1(1)norm(b), and the outputrv1(7)norm(b-A*x2)

You can follow the progress ofQMR.通过从初始估计开始(迭代数字0)开始在每次迭代时绘制相对残差。

半机(0:IT1,RV1 / NORM(B),'-o');xlabel('迭代号');ylabel(“相对残差”);

参考

[1] Barrett, R., M. Berry, T. F. Chan, et al.,Templates for the Solution of Linear Systems: Building Blocks for Iterative Methods,暹罗,费城,1994年。

[2]弗氏,罗兰W.和NÖELM.NACHTIGAL,“QMR:非封闭仪线性系统的准剩余残余方法”,SIAM Journal: Numer. Math.60,1991,第315-339页。

在R2006A之前介绍

这个主题有用吗?