tfqmr
Transpose-free quasi-minimal residual method
Syntax
x = tfqmr(A,b)
x = tfqmr(afun,b)
x = tfqmr(a,b,tol)
x = tfqmr(a,b,tol,maxit)
x = tfqmr(a,b,tol,maxit,m)
x = tfqmr(a,b,tol,maxit,m1,m2,x0)
[x,flag] = tfqmr(a,b,...)
[x,flag,relres] = tfqmr(A,b,...)
[x,flag,relres,y]y(A,b,...)
[x,flag,relres,iter,resvec] = tfqmr(a,b,...)
Description
x = tfqmr(A,b)
attempts to solve the system of linear equations斧头=b
forx
。这n
-经过-n
系数矩阵A
must be square and the right-hand side column vectorb
must have lengthn
。
x = tfqmr(afun,b)
接受函数句柄,好玩儿
,而不是矩阵A
。这function,afun(x)
, accepts a vector inputx
和returns the matrix-vector product斧头
。In all of the following syntaxes, you can replaceA
by好玩儿
。Parameterizing Functionsexplains how to provide additional parameters to the function好玩儿
。
x = tfqmr(a,b,tol)
指定该方法的耐受性。如果tol
is[]
thentfqmr
uses the default, 1e-6.
x = tfqmr(a,b,tol,maxit)
指定最大迭代次数。如果最大
is[]
thentfqmr
uses the default,min(N,20)
。
x = tfqmr(a,b,tol,maxit,m)
和x = tfqmr(a,b,tol,maxit,m1,m2)
使用预调整器m
或者M = M1*M2
和effectively solve the systemA*inv(M)*x = B
forx
。如果M
is[]
then a preconditioner is not applied.M
may be a function handlemfun
such thatmfun(x)
returnsm\x
。
x = tfqmr(a,b,tol,maxit,m1,m2,x0)
specifies the initial guess. Ifx0
is[]
thentfqmr
使用默认值,全零向量。
[x,flag] = tfqmr(a,b,...)
also returns a convergence flag:
旗帜 |
Convergence |
---|---|
|
|
|
|
|
Preconditioner |
|
|
|
One of the scalar quantities calculated during |
[x,flag,relres] = tfqmr(A,b,...)
还返回相对残差norm(b-A*x)/norm(b)
。如果flag
是0,然后relres <= tol
。
[x,flag,relres,y]y(A,b,...)
also returns the iteration number at whichx
was computed:0 <= iter <= maxit
。
[x,flag,relres,iter,resvec] = tfqmr(a,b,...)
还返回每次迭代中残留规范的向量,包括norm(b-A*x0)
。
Examples
将TFQMR与矩阵或函数手柄输入输入
This example shows how to usetfqmr
with a matrix input and with a function input.
n = 100;on =一个(n,1);a = spdiags([-2*on 4*on-on],-1:1,n,n);b = sum(a,2);TOL = 1E-8;最大值= 15;m1 = spdiags([on/(-2)on],-1:0,n,n);m2 = spdiags([4*on -on],0:1,n,n);x = tfqmr(a,b,tol,maxit,m1,m2,[]);
您还可以将矩阵矢量产品功能作为输入:
函数y = afun(x,n)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);x1 = tfqmr(@(x)afun(x,n),b,tol,maxit,m1,m2);
如果申请
是适合与QMR
, it may be used withtfqmr
by wrapping it in an anonymous function:
x1 = tfqmr(@(x)applaop(x,'notransp'),b,tol,maxit,m1,m2);
Using tfqmr with a Preconditioner
此示例演示了使用预处理。
LoadA = west0479
, a real 479-by-479 nonsymmetric sparse matrix.
loadwest0479; A = west0479;
Defineb
so that the true solution is a vector of all ones.
b = full(sum(a,2));
设置公差和最大迭代次数。
tol = 1e-12; maxit = 20;
采用tfqmr
to find a solution at the requested tolerance and number of iterations.
[x0,fl0,rr0,it0,rv0] = tfqmr(a,b,tol,maxit);
fl0
is 1 becausetfqmr
不收敛到请求的公差1e-12
之内the requested 20 iterations. The seventeenth iterate is the best approximate solution and is the one returned as indicated byit0 = 17
。MATLAB®将剩余历史存储在rv0
。
Plot the behavior oftfqmr
。
半学(0:Maxit,RV0(1:Maxit+1)/Norm(b),'-o'); xlabel('迭代编号'); ylabel(“相对残留”);
Note that likebicgstab
,tfqmr
keeps track of half iterations. The plot shows that the solution does not converge. You can use a preconditioner to improve the outcome.
用伊卢
, since the matrixA
is nonsymmetric.
[L,U] = ilu(A,struct('type','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('type','ilutp','droptol', 1 e-6));(x1, fl1 rr1、it1 rv1] =tfqmr(A,b,tol,maxit,L,U);
fl1
is 0 becausetfqmr
drives the relative residual to4.1410E-014
(the value ofRR1
). The relative residual is less than the prescribed tolerance of1e-12
at the sixth iteration (the value ofit1
) when preconditioned by the incomplete LU factorization with a drop tolerance of1e-6
。输出RV1(1)
isnorm(b)
, and the outputrv1(7)
isnorm(b-A*x2)
。
You can follow the progress oftfqmr
通过从初始估计开始(迭代号0)开始在每次迭代处绘制相对残差。
半学(0:0.5:IT1,RV1/Norm(b),'-o'); xlabel('迭代编号'); ylabel(“相对残留”);