數(shù)值實驗報告-實驗三_第1頁
數(shù)值實驗報告-實驗三_第2頁
數(shù)值實驗報告-實驗三_第3頁
數(shù)值實驗報告-實驗三_第4頁
數(shù)值實驗報告-實驗三_第5頁
已閱讀5頁,還剩11頁未讀 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

數(shù)值實驗報告實驗題三數(shù)值實驗報告實驗題三實驗3.1多項式插值的振蕩現(xiàn)象3.1.1問題提出考慮一個固定區(qū)間上用插值逼近一個函數(shù)。顯然拉格朗日插值中使用的節(jié)點越多,插值多項式的次數(shù)就越高。我們自然關心插值多項式的次數(shù)增加時,是否也更加靠近被逼近的函數(shù)。龍格(Runge)給出的一個例子是極著名并富有啟發(fā)性的。設區(qū)間[-1,1]上函數(shù) 考慮的一個等距劃分,分點為 則拉格朗日插值多項式為 其中是次拉格朗日插值基函數(shù)。3.1.2實驗內容3.1.2.1第一小題選擇不斷增大的分點數(shù)目,畫出原函數(shù)及插值多項式函數(shù)在上的圖像,比較并分析實驗結果。(1)MATLAB代碼程序3.1.1:拉格朗日插值公式函數(shù)lag_interp.mfunctionf_n=lag_interp(xn,yn,x0)%LagrangeInterpolation%%Type1:y=lag_interp(xn,yn,x0)%Ifxisinput,thenthefunctionreturnsanumericalvalueLn(x0),which%isequaltovpa(subs(lag_interp(xn,yn),x,x0)).%%Type2:y=lag_interp(xn,yn)%Ifxisnotinput,thethefunctionreturnsansymbolicfunctionLn(x).%Safeguardsforinputarguments[dim1,dim]=size(xn);ifdim1~=1error('xnmustbealinevector.')endifdim<=1error('Theremustbeatleast2points.')end[dim1,dim2]=size(yn);ifdim1~=1error('ynmustbealinevector.')endifdim2~=dimerror('Thedimentionofxnandynmustagree.')end%Langrangeinterpolationsymsx;f_result=0;fori=1:diml=1;forj=1:dimifi~=jl=l*(x-xn(j))/(xn(i)-xn(j));endendf_result=f_result+yn(i)*l;endifnargin==2%Ifxisnotinput,thethefunctionreturnsansymbolicfunctionLn(x).f_n=f_result;elseifnargin==3%Ifxisinput,thenthefunctionreturnsanumericalvalueLn(x0).f_n=vpa(subs(f_result,x,x0));end程序3.1.2:產(chǎn)生n個分點的函數(shù)gen_eqpts.mfunctionxn=gen_eqpts(left,right,n)%Returnsann-dimentionallinevectorofequidistantpointsoninterval[left,right]%%Type:xn=gen_eqpts(left,right,n)%%'left'isthelowerboundaryoftheinterval.%'right'isthelowerboundaryoftheinterval.%'n'isthenumberofequidistantpoints.nmustbeanintegergreaterorequalto2.%ThismfileiscodedbySteveZhao.Forreferenceonly.%%Theauthorwillnotberesponsibleforanypotentialconsequencesthatmay%causedbythisfile.%%(c)20163gStudio.Allrightsreserved%Safeguardsforinputargumentsifleft>=righterror('Theupperboundmustbegreaterthanthelowerbound.')endifmod(n,1)~=0error('nmustbeaninteger.')endifn<2error('nmustbeatleast2.')end%Startgeneratingxn=zeros(1,n);xn(1)=left;fori=2:nxn(i)=left+(i-1)/(n-1)*(right-left);end程序3.1.3:第一小題主程序ex311.m%Experiment3.1(1)%ComparisonofLagrangeInterpolationandoriginalfunction%%ThismfileiscodedbySteveZhao.Forreferenceonly.%%Theauthorwillnotberesponsibleforanypotentialconsequencesthatmay%causedbythisfile.%%(c)20163gStudio.Allrightsreservedn=input('Pleaseinputthenumberofequidistantpoints.n=£o');holdonsymsx;f=@(x)1./(1+25*x.^2);x0=linspace(-1,1);y0=f(x0);plot(x0,y0,'-k');xn=gen_eqpts(-1,1,n);yn=f(xn);plot(x0,lag_interp(xn,yn,x0),'--b');(2)問題的探索n=2時,原函數(shù)圖像(黑色實線)和插值函數(shù)圖像(藍色虛線)如圖所示n=3時,圖像如圖所示n=4、5,圖像如圖所示:n=6、7時,圖像如圖所示n=8、9時,圖像如圖所示(3)結論我們可以發(fā)現(xiàn),n為6時,插值函數(shù)的走勢與實際函數(shù)較為接近。然而n越大時,雖然與原函數(shù)的值更為接近,但在較遠處與函數(shù)的誤差越來越大。3.1.2.2第二小題的求解選擇不斷增大的分點數(shù)目,畫出原函數(shù)及插值多項式函數(shù)在上的圖像,比較并分析實驗結果。(1)MATLAB代碼程序3.1.4:第二小題主程序ex312.m%Experiment3.1(2)%ComparisonofLagrangeInterpolationandoriginalfunction%%ThismfileiscodedbySteveZhao.Forreferenceonly.%%Theauthorwillnotberesponsibleforanypotentialconsequencesthatmay%causedbythisfile.%%(c)20163gStudio.Allrightsreservedn=input('Pleaseinputthenumberofequidistantpoints.n=');symsx;g=@(x)x./(1+x.^4);h=@(x)atan(x);x0=linspace(-5,5);y01=g(x0);y02=h(x0);xn=gen_eqpts(-5,5,n);yn1=g(xn);yn2=h(xn);subplot(1,2,1),holdon,plot(x0,y01,'-k'),plot(x0,lag_interp(xn,yn1,x0),'--b');subplot(1,2,2),holdon,plot(x0,y02,'-k'),plot(x0,lag_interp(xn,yn2,x0),'--b');(2)問題的探索時,原函數(shù)(黑色實線)及其插值函數(shù)(藍色虛線)的圖像如圖所示:時,圖像如圖所示、5時,圖像如圖所示:、7時,圖像如圖所示:(3)結論我們可以發(fā)現(xiàn)Lagrange插值對于趨勢變化較大的函數(shù)擬合效果不是很好,且次數(shù)越高,振蕩越明顯。3.1.2.3第三小題的求解本小題要求通過構造Chebyshev點替代等距點,檢驗Lagrange的效果。(1)MATLAB程序程序3.1.5:構造Chebyshev點的函數(shù)gen_chpts.mfunctionxn=gen_chpts(left,right,n)%Returnsann-dimentionallinevectorofchebyshevpointsoninterval[left,right]%%Type:xn=gen_chpts(left,right,n)%%'left'isthelowerboundaryoftheinterval.%'right'isthelowerboundaryoftheinterval.%'n'isthenumberofequidistantpoints.nmustbeanintegergreaterorequalto2.%ThismfileiscodedbySteveZhao.Forreferenceonly.%%Theauthorwillnotberesponsibleforanypotentialconsequencesthatmay%causedbythisfile.%%(c)20163gStudio.Allrightsreserved%Safeguardsforinputargumentsifleft>=righterror('Theupperboundmustbegreaterthanthelowerbound.')endifmod(n,1)~=0error('nmustbeaninteger.')endifn<2error('nmustbeatleast2.')end%Startgeneratingxn=zeros(1,n);n=n-1;xn(1)=left;fori=1:(n+1)xn(i)=(right+left)/2+(right-left)/2*cos((2*i-1)*pi/2/(n+1));end程序3.1.6:第三小題主程序ex313.m%Experiment3.1(3)%ComparisonofLagrangeInterpolationandoriginalfunctionusingChebyshevpoints.%%ThismfileiscodedbySteveZhao.Forreferenceonly.%%Theauthorwillnotberesponsibleforanypotentialconsequencesthatmay%causedbythisfile.%%(c)20163gStudio.Allrightsreservedn=input('PleaseinputthenumberofChebyshevpoints.n=');holdonsymsx;f=@(x)1./(1+25*x.^2);x0=linspace(-1,1);y0=f(x0);plot(x0,y0,'-k');xn=gen_chpts(-1,1,n);yn=f(xn);plot(x0,lag_interp(xn,yn,x0),'--b');(2)問題的探究時,原函數(shù)(黑色實線)及其插值函數(shù)(藍色虛線)的圖像如圖所示:時,圖像如圖所示:、5時,圖像如圖所示:、7時,圖像如圖所示:(3)實驗結論可以發(fā)現(xiàn),在中,等距點與Chebyshev點的擬合程度差距不明顯。實驗3.2樣條插值的收斂性3.2.1問題的提出在探究完多項式插值后,本實驗擬檢驗樣條插值的收斂性。3.2.2實驗內容3.2.2.1第一小題的求解隨節(jié)點個數(shù)增加,比較被逼近函數(shù)和樣條插值函數(shù)誤差的變化情況。分析所得結果并于Lagrange多項式插值比較。(1)MATLAB程序程序3.2.1:第一小題主程序ex321.m%Experiment3.2(1)%ComparisonamongCubicSplineInterpolation,LagrangeInterpolationand%originalfunction.%%ThismfileiscodedbySteveZhao.Forreferenceonly.%%Theauthorwillnotberesponsibleforanypotentialconsequencesthatmay%causedbythisfile.%%(c)20163gStudio.Allrightsreservedn=input('Pleaseinputthenumberofequidistantpoints.n=');holdonsymsx;f=@(x)1./(1+25*x.^2);x0=linspace(-1,1);y0=f(x0);plot(x0,y0,'-k');xn=gen_eqpts(-1,1,n);yn=f(xn);plot(x0,spline(xn,yn,x0),'-b');plot(x0,lag_interp(xn,yn,x0),'--g');(2)問題的探究當、3、4時,原函數(shù)(黑色實線)、樣條插值(藍色實線)與多項式插值(綠色虛線)圖像如圖所示:時,兩擬合圖像開始分離,圖像如圖所示、7時,圖像如圖所示(3)結論可以發(fā)現(xiàn),樣條插值的振蕩較多項式插值更小。3.2.2.2第二小題的求解畫出給定數(shù)據(jù)的三次樣條插值曲線。(1)MATLAB程序程序3.2.2:第二小題主程序ex322.m%Experiment3.2(2)%Usesplinedatainterpolationwithslopesatbothendings%%ThismfileiscodedbySteveZhao.Forreferenceonly.%%Theauthorwillnotberesponsibleforanypotentialconsequencesthatmay%causedbythisfile.%%(c)20163gStudio.Allrightsreservedx0=0:10;y0=[0.00.791.532.191.713.033.272.893.063.193.29];pp=csape(x0,y0,[0.80.2]);x=linspace(0,10);plot(x,ppval(pp,x),'-b')(2)結果通過MATLAB的csape命令,我們可以輕松畫出本題所求的圖形:3.3思考題一3.3.1問題的提出在丘陵地帶測量高程,和方向每隔100米測一個點,得高程數(shù)據(jù)。用二維插值函數(shù)進行插值,并由此找出最高點和該點的高程。3.3.2問題的求解由于線性插值效果不佳,此處使用二元三次樣條插值。(1)MATLAB程序程序3.3:思考題一主程序ex33.m%Exp

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論