gmres源程序matlab.doc
《gmres源程序matlab.doc》由会员分享,可在线阅读,更多相关《gmres源程序matlab.doc(13页珍藏版)》请在课桌文档上搜索。
1、-function *,flag,relres,iter,resvec = gmres(A,b,restart,tol,ma*it,M1,M2,*,varargin)%GMRES Generalized Minimum Residual Method.% * = GMRES(A,B) attempts to solve the system of linear equations A* = B% for *. The N-by-N coefficient matri* A must be square and the right% hand side column vector B must
2、have length N. This uses the unrestarted% method with MIN(N,10) total iterations.% * = GMRES(AFUN,B) accepts a function handle AFUN instead of the matri*% A. AFUN(*) accepts a vector input * and returns the matri*-vector% product A*. In all of the following synta*es, you can replace A by% AFUN.% * =
3、 GMRES(A,B,RESTART) restarts the method every RESTART iterations.% If RESTART is N or then GMRES uses the unrestarted method as above.% * = GMRES(A,B,RESTART,TOL) specifies the tolerance of the method. If% TOL is then GMRES uses the default, 1e-6.% * = GMRES(A,B,RESTART,TOL,MA*IT) specifies the ma*i
4、mum number of outer% iterations. Note: the total number of iterations is RESTART*MA*IT. If% MA*IT is then GMRES uses the default, MIN(N/RESTART,10). If RESTART% is N or then the total number of iterations is MA*IT.% * = GMRES(A,B,RESTART,TOL,MA*IT,M) and% * = GMRES(A,B,RESTART,TOL,MA*IT,M1,M2) use p
5、reconditioner M or M=M1*M2% and effectively solve the system inv(M)*A* = inv(M)*B for *. If M is% then a preconditioner is not applied. M may be a function handle% returning M*.% * = GMRES(A,B,RESTART,TOL,MA*IT,M1,M2,*0) specifies the first initial% guess. If *0 is then GMRES uses the default, an al
6、l zero vector.% *,FLAG = GMRES(A,B,.) also returns a convergence FLAG:% 0 GMRES converged to the desired tolerance TOL within MA*IT iterations.% 1 GMRES iterated MA*IT times but did not converge.% 2 preconditioner M was ill-conditioned.% 3 GMRES stagnated (two consecutive iterates were the same).% *
7、,FLAG,RELRES = GMRES(A,B,.) also returns the relative residual% NORM(B-A*)/NORM(B). If FLAG is 0, then RELRES = TOL. Note with% preconditioners M1,M2, the residual is NORM(M2(M1(B-A*).% *,FLAG,RELRES,ITER = GMRES(A,B,.) also returns both the outer and% inner iteration numbers at which * was computed
8、: 0 = ITER(1) = MA*IT% and 0 = ITER(2) = RESTART.% *,FLAG,RELRES,ITER,RESVEC = GMRES(A,B,.) also returns a vector of% the residual norms at each inner iteration, including NORM(B-A*0).% Note with preconditioners M1,M2, the residual is NORM(M2(M1(B-A*).% E*ample:% n = 21; A = gallery(wilk,n); b = sum
9、(A,2);% tol = 1e-12; ma*it = 15; M = diag(10:-1:1 1 1:10);% * = gmres(A,b,10,tol,ma*it,M);% Or, use this matri*-vector product function% %-% function y = afun(*,n)% y = 0; *(1:n-1) + (n-1)/2:-1:0); (1:(n-1)/2).*+*(2:n); 0;% %-% and this preconditioner backsolve function% %-% function y = mfun(r,n)%
10、y = r ./ (n-1)/2:-1:1); 1; (1:(n-1)/2);% %-% as inputs to GMRES:% *1 = gmres(*)afun(*,n),b,10,tol,ma*it,(*)mfun(*,n);% Class support for inputs A,B,M1,M2,*0 and the output of AFUN:% float: double% See also BICG, BICGSTAB, BICGSTABL, CGS, LSQR, MINRES, PCG, QMR, SYMMLQ,% TFQMR, ILU, FUNCTION_HANDLE.%
11、 References% H.F. Walker, Implementation of the GMRES Method Using Householder% Transformations, SIAM J. Sci. Comp. Vol 9. No 1. January 1988.% Copyright 1984-2010 The MathWorks, Inc.% $Revision: 1.21.4.13 $ $Date: 2010/02/25 08:11:48 $if (nargin 2) error(MATLAB:gmres:NumInputs,Not enough input argu
12、ments.);end% Determine whether A is a matri* or a function.atype,afun,afcnstr = iterchk(A);if strcmp(atype,matri*) % Check matri* and right hand side vector inputs have appropriate sizes m,n = size(A); if (m = n) error(MATLAB:gmres:SquareMatri*,Matri* must be square.); end if isequal(size(b),m,1) er
13、ror(MATLAB:gmres:VectorSize, %s %d %s, . Right hand side must be a column vector of length, m,. to match the coefficient matri*.); endelse m = size(b,1); n = m; if iscolumn(b) error(MATLAB:gmres:Vector,Right hand side must be a column vector.); endend% Assign default values to unspecified parameters
14、if (nargin 3) | isempty(restart) | (restart = n) restarted = false;else restarted = true;endif (nargin 4) | isempty(tol) tol = 1e-6;endwarned = 0;if tol = 1 warning(MATLAB:gmres:tooBigTolerance, . strcat(Input tol is bigger than 1 n,. Try to use a smaller tolerance); warned = 1; tol = 1-eps;endif (n
15、argin n warning(MATLAB:gmres:tooManyInnerIts, RESTART is %d %sn%s %d., . restart, but it should be bounded by SIZE(A,1)., . Setting RESTART to, n); restart = n; end inner = restart;else outer = 1; if ma*it n warning(MATLAB:gmres:tooManyInnerIts, MA*IT is %d %sn%s %d., . ma*it, but it should be bound
16、ed by SIZE(A,1)., . Setting MA*IT to, n); ma*it = n; end inner = ma*it;end% Check for all zero right hand side vector = all zero solutionn2b = norm(b); % Norm of rhs vector, bif (n2b = 0) % if rhs vector is all zeros * = zeros(n,1); % then solution is all zeros flag = 0; % a valid solution has been
17、obtained relres = 0; % the relative residual is actually 0/0 iter = 0 0; % no iterations need be performed resvec = 0; % resvec(1) = norm(b-A*) = norm(0) if (nargout = 6) & isempty(M1) e*istM1 = 1; m1type,m1fun,m1fcnstr = iterchk(M1); if strcmp(m1type,matri*) if isequal(size(M1),m,m) error(MATLAB:gm
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- gmres 源程序 matlab

链接地址:https://www.desk33.com/p-21292.html