資源描述:
《gmres源程序 matlab》由會員上傳分享,免費在線閱讀,更多相關內容在教育資源-天天文庫。
1、function[x,flag,relres,iter,resvec]=gmres(A,b,restart,tol,maxit,M1,M2,x,varargin)%GMRESGeneralizedMinimumResidualMethod.%X=GMRES(A,B)attemptstosolvethesystemoflinearequationsA*X=B%forX.TheN-by-NcoefficientmatrixAmustbesquareandtheright%handsidecolumnvec
2、torBmusthavelengthN.Thisusestheunrestarted%methodwithMIN(N,10)totaliterations.%%X=GMRES(AFUN,B)acceptsafunctionhandleAFUNinsteadofthematrix%A.AFUN(X)acceptsavectorinputXandreturnsthematrix-vector%productA*X.Inallofthefollowingsyntaxes,youcanreplaceAby%A
3、FUN.%%X=GMRES(A,B,RESTART)restartsthemethodeveryRESTARTiterations.%IfRESTARTisNor[]thenGMRESusestheunrestartedmethodasabove.%%X=GMRES(A,B,RESTART,TOL)specifiesthetoleranceofthemethod.If%TOLis[]thenGMRESusesthedefault,1e-6.%%X=GMRES(A,B,RESTART,TOL,MAXIT
4、)specifiesthemaximumnumberofouter%iterations.Note:thetotalnumberofiterationsisRESTART*MAXIT.If%MAXITis[]thenGMRESusesthedefault,MIN(N/RESTART,10).IfRESTART%isNor[]thenthetotalnumberofiterationsisMAXIT.%%X=GMRES(A,B,RESTART,TOL,MAXIT,M)and%X=GMRES(A,B,RE
5、START,TOL,MAXIT,M1,M2)usepreconditionerMorM=M1*M2%andeffectivelysolvethesysteminv(M)*A*X=inv(M)*BforX.IfMis%[]thenapreconditionerisnotapplied.Mmaybeafunctionhandle%returningMX.%%X=GMRES(A,B,RESTART,TOL,MAXIT,M1,M2,X0)specifiesthefirstinitial%guess.IfX0
6、is[]thenGMRESusesthedefault,anallzerovector.%%[X,FLAG]=GMRES(A,B,...)alsoreturnsaconvergenceFLAG:%0GMRESconvergedtothedesiredtoleranceTOLwithinMAXITiterations.%1GMRESiteratedMAXITtimesbutdidnotconverge.%2preconditionerMwasill-conditioned.%3GMRESstagnate
7、d(twoconsecutiveiterateswerethesame).%%[X,FLAG,RELRES]=GMRES(A,B,...)alsoreturnstherelativeresidual%NORM(B-A*X)/NORM(B).IfFLAGis0,thenRELRES<=TOL.Notewith%preconditionersM1,M2,theresidualisNORM(M2(M1(B-A*X))).%%[X,FLAG,RELRES,ITER]=GMRES(A,B,...)alsor
8、eturnsboththeouterand%inneriterationnumbersatwhichXwascomputed:0<=ITER(1)<=MAXIT%and0<=ITER(2)<=RESTART.%%[X,FLAG,RELRES,ITER,RESVEC]=GMRES(A,B,...)alsoreturnsavectorof%theresidualnormsateachinneriteration,includingNORM(B-A*X0).%