Documentation

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斧头=bforx。这n-经过-n系数矩阵Amust be square and the right-hand side column vectorbmust 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 replaceAby好玩儿Parameterizing Functionsexplains how to provide additional parameters to the function好玩儿

x = tfqmr(a,b,tol)指定该方法的耐受性。如果tolis[]thentfqmruses the default, 1e-6.

x = tfqmr(a,b,tol,maxit)指定最大迭代次数。如果最大is[]thentfqmruses 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 = Bforx。如果Mis[]then a preconditioner is not applied.Mmay be a function handlemfunsuch thatmfun(x)returnsm\x

x = tfqmr(a,b,tol,maxit,m1,m2,x0)specifies the initial guess. Ifx0is[]thentfqmr使用默认值,全零向量。

[x,flag] = tfqmr(a,b,...)also returns a convergence flag:

旗帜

Convergence

0

tfqmrconverged to the desired tolerancetol之内最大iterations.

1

tfqmr迭代最大times but did not converge.

2

Preconditionermwas ill-conditioned.

3

tfqmrstagnated. (Two consecutive iterates were the same.)

4

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

[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 whichxwas computed:0 <= iter <= maxit

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

Examples

将TFQMR与矩阵或函数手柄输入输入

This example shows how to usetfqmrwith 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 withtfqmrby 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;

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

b = full(sum(a,2));

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

tol = 1e-12; maxit = 20;

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

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

fl0is 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,tfqmrkeeps track of half iterations. The plot shows that the solution does not converge. You can use a preconditioner to improve the outcome.

伊卢, since the matrixAis 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);

fl1is 0 becausetfqmrdrives 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)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(“相对残留”);

Extended Capabilities