MATLAB牛頓法源代碼

MATLAB牛頓法源代碼

ID:1038285

大小:29.50 KB

頁數:10頁

時間:2017-11-07

MATLAB牛頓法源代碼_第1頁
MATLAB牛頓法源代碼_第2頁
MATLAB牛頓法源代碼_第3頁
MATLAB牛頓法源代碼_第4頁
MATLAB牛頓法源代碼_第5頁
資源描述:

《MATLAB牛頓法源代碼》由會員上傳分享,免費在線閱讀,更多相關內容在行業(yè)資料-天天文庫。

1、MATLAB牛頓法源代碼function[sol,it_hist,ierr]=nsol(x,f,tol,parms)%Newtonsolver,locallyconvergent%solverforf(x)=0%%HybridofNewton,Shamanskii,Chord%%C.T.Kelley,November26,1993%%Thiscodecomeswithnoguaranteeorwarrantyofanykind.%%function[sol,it_hist,ierr]=nsol(x,f,tol,parms)%%inputs:%???????initialiterate=

2、x%??function=f%???????tol=[atol,rtol]relative/absolute%???errortolerances%parms=[maxit,isham,rsham]%???maxit=maxmiumnumberofiterations%????default=40%??isham,rsham:TheJacobianmatrixis%??computedandfactoredafterisham%??????????????updatesofxorwhenevertheratio%??ofsuccessiveinfinitynormsofthe%????

3、??????????nonlinearresidualexceedsrsham.%???isham=1,rsham=0isNewton'smethod,%???isham=-1,rsham=1isthechordmethod,%???isham=m,rsham=1istheShamanskiimethod%????????????defaults=[40,1000,.5]%%output:%sol=solution%it_hist=infinitynormsofnonlinearresiduals%???fortheiteration%ierr=0uponsuccessfultermi

4、nation%ierr=1ifeitheraftermaxititerations%????????????theterminationcriterionisnotsatsified%????????????ortheratioofsuccessivenonlinearresiduals%????????????exceeds1.Inthislattercase,theiteration%????isterminted.%%%internalparameter:%??????debug=turnson/offiterationstatisticsdisplayas%??????????

5、????theiterationprogresses%%Requires:diffjac.m,dirder.m%%Hereisanexample.Theexamplecomputespiasarootofsin(x)%withNewton'smethodandplotstheiterationhistory.%%%x=3;tol=[1.d-6,1.d-6];params=[40,1,0];%[result,errs,it_hist]=nsol(x,'sin',tol,params);%result%semilogy(errs)%%%setthedebugparameter,1turns

6、displayon,otherwiseoff%debug=0;%%initializeit_hist,ierr,andsettheiterationparameters%ierr=0;maxit=40;isham=1000;rsham=.5;ifnargin==4maxit=parms(1);isham=parms(2);rsham=parms(3);endrtol=tol(2);atol=tol(1);it_hist=[];n=length(x);fnrm=1;itc=0;%%evaluatefattheinitialiterate%computethestoptolerance%f

7、0=feval(f,x);fnrm=norm(f0,inf);it_hist=[it_hist,fnrm];fnrmo=1;itsham=isham;stop_tol=atol+rtol*fnrm;%%mainiterationloop%while(fnrm>stop_tol&itc

當前文檔最多預覽五頁,下載文檔查看全文

此文檔下載收益歸作者所有

當前文檔最多預覽五頁,下載文檔查看全文
溫馨提示:
1. 部分包含數學公式或PPT動畫的文件,查看預覽時可能會顯示錯亂或異常,文件下載后無此問題,請放心下載。
2. 本文檔由用戶上傳,版權歸屬用戶,天天文庫負責整理代發(fā)布。如果您對本文檔版權有爭議請及時聯系客服。
3. 下載前請仔細閱讀文檔內容,確認文檔內容符合您的需求后進行下載,若出現內容與標題不符可向本站投訴處理。
4. 下載文檔時可能由于網絡波動等原因無法下載或下載錯誤,付費完成后未能成功下載的用戶請聯系客服處理。