资源描述:
《Broyden方法求解非线性方程组的Matlab实现.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Broyden方法求解非线性方程组的Matlab实现注:matlab代码来自网络,仅供学习参考。1.把以下代码复制在一个.m文件上function[sol,it_hist,ierr]=brsola(x,f,tol,parms)%Broyden'sMethodsolver,globallyconvergent%solverforf(x)=0,Armijorule,onevectorstorage%%Thiscodecomeswithnoguaranteeorwarrantyofanykind.%%fu
2、nction[sol,it_hist,ierr]=brsola(x,f,tol,parms)%%inputs:%initialiterate=x%function=f%tol=[atol,rtol]relative/absolute%errortolerancesforthenonlineariteration%parms=[maxit,maxdim]%maxit=maxmiumnumberofnonlineariterations%default=40%maxdim=maximumnumberof
3、Broydeniterations%beforerestart,somaxdim-1vectorsare%stored%default=40%%output:%sol=solution%it_hist(maxit,3)=scaledl2normsofnonlinearresiduals%fortheiteration,numberfunctionevaluations,%andnumberofsteplengthreductions%ierr=0uponsuccessfultermination%i
4、err=1ifaftermaxititerations%theterminationcriterionisnotsatsified.%ierr=2failureinthelinesearch.Theiteration%isterminatediftoomanysteplengthreductions%aretaken.%%%internalparameter:%debug=turnson/offiterationstatisticsdisplayas%theiterationprogresses%%
5、alpha=1.d-4,parametertomeasuresufficientdecrease%%maxarm=10,maximumnumberofsteplengthreductionsbefore%failureisreported%%setthedebugparameter,1turnsdisplayon,otherwiseoff%debug=1;%%initializeit_hist,ierr,andsettheiterationparameters%ierr=0;maxit=40;max
6、dim=39;it_histx=zeros(maxit,3);maxarm=10;%ifnargin==4maxit=parms(1);maxdim=parms(2)-1;endrtol=tol(2);atol=tol(1);n=length(x);fnrm=1;itc=0;nbroy=0;%%evaluatefattheinitialiterate%computethestoptolerance%f0=feval(f,x);fc=f0;fnrm=norm(f0)/sqrt(n);it_hist(i
7、tc+1)=fnrm;it_histx(itc+1,1)=fnrm;it_histx(itc+1,2)=0;it_histx(itc+1,3)=0;fnrmo=1;stop_tol=atol+rtol*fnrm;outstat(itc+1,:)=[itcfnrm00];%%terminateonentry?%iffnrm8、stp_nrm=zeros(maxdim,1);lam_rec=ones(maxdim,1);%%Settheinitialstepto-F,computethestepnorm%lambda=1;stp(:,1)=-fc;stp_nrm(1)=stp(:,1)'*stp(:,1);%%mainiterationloop%while(itc