版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、MATLAB 作 業(yè) 4 參 考答案MATLAB作業(yè)四參考答案1、用y sin(10t2 3)在(0, 3)區(qū)間內(nèi)生成一組較稀疏的數(shù)據(jù),并用一維數(shù)據(jù)插值的 方法對給出的數(shù)據(jù)進(jìn)行曲線擬合,并將結(jié)果與理論曲線相比較?!厩蠼狻款愃朴谏厦娴睦樱梢杂脦缀跻恢碌恼Z句得出樣本數(shù)據(jù)和插值效果。>> t=0:0.2:3;y=sin(10*t.A2+3); plot(t,y,'o')ezplot('sin( 102+3)',0,3); hold onx1=0:0.001:3; y1=i nterp1(t,y,x1,'spli ne');plot(x1
2、,y1)由于曲線本身變換太大,所以在目前選定的樣本點(diǎn)下是不可能得出理想插值效果的,因?yàn)?樣本數(shù)據(jù)提供的信息量不夠。為了得到好的插值效果,必須增大樣本數(shù)據(jù)的信息量,對本例 來說,必須在快變化區(qū)域減小樣本點(diǎn)的步長。>> hold offt=0:0.1:1,1.1:0.04:3; y=sin( 10X2+3); plot(t,y,'o')ezplot('sin( 102+3)',0,3); hold onx1=0:0.001:3; y1=i nterp1(t,y,x1,'spli ne');plot(x1,y1)2、 用f(x,y) Vex
3、 y sin (xy2 x2y)原型函數(shù)生成一組網(wǎng)絡(luò)數(shù)據(jù)或隨機(jī)數(shù)據(jù),分別擬3x y合出曲面,并和原曲面進(jìn)行比較求解】由下面的語句可以直接生成一組網(wǎng)格數(shù)據(jù),用下面語句還可以還繪制出給定樣本 點(diǎn)是三維表面圖。>> x,y=meshgrid(0.2:0.2:2);z=exp(-x.A2-y.A4).*si n(x.*y.A2+x.A2.*y)./(3*x43+y);surf(x,y,z)選擇新的密集網(wǎng)格,則可以通過二元插值得出插值曲面。對比插值結(jié)果和新網(wǎng)格下的函數(shù) 值精確解,則可以繪制出絕對插值誤差曲面。由插值結(jié)果可見精度是令人滿意的。>> x1,y1=meshgrid(0.
4、2:0.02:2);z1=interp2(x,y,z,x1,y1,'spline');surf(x1,y1,z1)>> z0=exp(-x1.A2-y1.A4).*sin(x1.*y1.A2+x1.A2.*y1)./(3*x1.A3+y1); surf(x1,y1,abs(z1-z0)現(xiàn)在假設(shè)已知的樣本點(diǎn)不是網(wǎng)格形式分布的,而是隨機(jī)分布的,則可以用下面語句生成樣 本點(diǎn),得出分布的二維、三維示意圖。>> x=0.2+1.8*rand(400,1); y=0.2+1.8*rand(400,1);% 仍生成 (0.2,2) 區(qū)間的均勻分布隨機(jī)數(shù)z=exp(-x
5、.A2-y.A4).*sin(x.*y.A2+x.A2.*y)./(3*x.A3+y);plot(x,y,'x')figure, plot3(x,y,z,'x')利用下面的語句可以得出三維插值結(jié)果 , 同時(shí)可以繪制出插值的絕對誤差曲面,可見插值結(jié)果還是很好的,但由于邊界樣本點(diǎn)信息不能保證,所以不能像網(wǎng)格數(shù)據(jù)那樣對 (0.2,2)區(qū)域,而只能選擇 (0.3,1.9) 區(qū)域進(jìn)行插值>> x1,y1=meshgrid(0.3:0.02:1.9);z仁griddata(x,y, z,x1,y1,'v4');surf(x1,y1,z1)>
6、> z0=exp(-x1.A2-y1.A4).*si n(x1.*y1.A2+x1.A2.*y1)./(3*x1.A3+y1);surf(x1,y1,abs(z1-z0)3、假設(shè)已知一組數(shù)據(jù),試用插值方法繪制出x ( 2,4.9)區(qū)間內(nèi)的光滑函數(shù)曲線,比較各種插值算法的優(yōu)劣。Xi-2-1.7-1.4-1.1-0.8-0.5-0.20.10.40.711.3yi.10289.11741.13158.14483.15656.16622.17332.1775.17853.17635.17109.16302Xi1.61.92.22.52.83.13.43.744.34.64.9Yi.15255.
7、1402.12655.11219.09768.08353.07015.05786.04687.03729.02914.02236【求解】用下面的語句可以立即得出給定樣本點(diǎn)數(shù)據(jù)的三次插值與樣條插值,得出的結(jié)果如,可見,用兩種插值方法對此例得出的結(jié)果幾乎一致,效果均很理想。>> x=-2,-1.7,-1.4,-1.1,-0.8,-0.5,-0.2,0.1,0.4,0.7,1,1.3,;y=0.10289,0.11741,0.13158,0.14483,0.15656,0.16622,0.17332,.0.1775,0.17853,0.17635,0.17109,0.16302,0.15
8、255,0.1402,.0.12655,0.11219,0.09768,0.08353,0.07019,0.05786,0.04687,.0.03729,0.02914,0.02236;x0=-2:0.02:4.9;y1=i nterp1(x,y,x0,'cubic');y2=i nterp1(x,y,x0,'spli ne');plot(x0,y1,':',x0,y2,x,y,'o')4、假設(shè)已知實(shí)測數(shù)據(jù)由下表給出,試對(x,y)在(0.1,0.1)(1.1,1.1)區(qū)域內(nèi)的點(diǎn)進(jìn)行插值,并用三維曲面的方式繪制出插值結(jié)果。yiX1
9、X2X3X4X5X6X7XX9X10X1100.10.20.30.40.50.60.70.80.911.10.1.83041.82727.82406.82098.81824.8161.81481.81463.81579.81853.823040.2.83172.83249.83584.84201.85125.86376.87975.89935.92263.94959.98010.3.83587.84345.85631.87466.89867.9284.963771.00451.05021.11.15290.4.84286.86013.88537.91865.959851.00861.06421
10、.12531.19041.2571.32220.5.85268.88251.92286.973461.03361.10191.17641.2541.33081.40171.46050.6r.86532.91049.968471.03831.1181.20461.29371.37931.45391.50861.53350.7r.88078.943961.02171.11181.21021.3111.40631.48591.53771.54841.50520.8.89904.982761.0821.19221.30611.41381.50211.55551.55731.49151.3460.9r.
11、920061.02661.14821.27681.40051.50341.56611.56781.48891.31561.04541r.943811.07521.21911.36241.48661.56841.58211.50321.3151.0155.624771.1.970231.12791.29291.44481.55641.59641.53411.34731.0321.61268.14763【求解】直接采用插值方法可以解決該問題,得出的插值曲面>> x,y=meshgrid(0.1:0.1:1.1);z=0.83041,0.82727,0.82406,0.82098,0.8
12、1824,0.8161,0.81481,0.81463,0.81579,0.81 853,0.82304;0.83172,0.83249,0.83584,0.84201,0.85125,0.86376,0.87975,0.89935,0.92263,0.949 59,0.9801;0.83587,0.84345,0.85631,0.87466,0.89867,0.9284,0.96377,1.0045,1.0502,1.1,1.152 9;0.84286,0.86013,0.88537,0.91865,0.95985,1.0086,1.0642,1.1253,1.1904,1.257,1.32
13、 22;0.85268,0.88251,0.92286,0.97346,1.0336,1.1019,1.1764,1.254,1.3308,1.4017,1.460 5;0.86532,0.91049,0.96847,1.0383,1.118,1.2046,1.2937,1.3793,1.4539,1.5086,1.5335;0.88078,0.94396,1.0217,1.1118,1.2102,1.311,1.4063,1.4859,1.5377,1.5484,1.5052;0.89904,0.98276,1.082,1.1922,1.3061,1.4138,1.5021,1.5555,1
14、.5573,1.4915,1.346; 0.92006,1.0266,1.1482,1.2768,1.4005,1.5034,1.5661,1.5678,1.4889,1.3156,1.0454;0.94381,1.0752,1.2191,1.3624,1.4866,1.5684,1.5821,1.5032,1.315,1.0155,0.62477;0.97023,1.1279,1.2929,1.4448,1.5564,1.5964,1.5341,1.3473,1.0321,0.61268,0.14763;x1,y1=meshgrid(0.1:0.02:1.1);z1=interp2(x,y,
15、z,x1,y1,'spline');surf(x1,y1,z1)axis(0.1,1.1,0.1,1.1,min(z1(:),max(z1(:)其實(shí),若光需要插值曲面而不追求插值數(shù)值的話,完全可以直接采用MATLABF的shadi nginterp 命令來實(shí)現(xiàn)??梢?,這樣的插值方法更好,得出的插值曲面更光滑。>> surf(x,y,z); shading interp5、習(xí)題 3和 4給出的數(shù)據(jù)分別為一元數(shù)據(jù)和二元數(shù)據(jù),試用分段三次樣條函數(shù)和 B 樣條函數(shù)對其進(jìn)行擬合?!厩蠼狻肯瓤紤]習(xí)題4,相應(yīng)的三次樣條插值和B-樣條插值原函數(shù)與導(dǎo)數(shù)函數(shù)分別為:>> x
16、=-2,-1.7,-1.4,-1.1,-0.8,-0.5,-0.2,0.1,0.4,0.7,1,1.3,.;y=0.10289,0.11741,0.13158,0.14483,0.15656,0.16622,0.17332,.0.1775,0.17853,0.17635,0.17109,0.16302,0.15255,0.1402,.0.12655,0.11219,0.09768,0.08353,0.07019,0.05786,0.04687,.0.03729,0.02914,0.02236;S=csapi(x,y); S1=spapi(6,x,y);fnplt(S); hold on; fn
17、plt(S1)>> Sd=fnder(S); Sd1=fnder(S1);fnplt(Sd), hold on; fnplt(Sd1)再考慮習(xí)題 5 中的數(shù)據(jù),原始數(shù)據(jù)不能直接用于樣條處理,因?yàn)?meshgrid() 函數(shù)產(chǎn)生的數(shù)據(jù)格式與要求的ndgrid()函數(shù)不一致,所以需要對數(shù)據(jù)進(jìn)行處理,其中需要的x和y均應(yīng)該是向量,而z是原來z矩陣的轉(zhuǎn)置,所以用下面的語句可以建立起三次樣條和B-樣條的插值模型,函數(shù)的表面圖所示,可見二者得出的結(jié)果很接近。>> x,y=meshgrid(0:0.1:1.1); z=0.83041,0.82727,0.82406,0.82098,0
18、.81824,0.8161,0.81481,0.81463,0.81579,0.81 853,0.82304;0.83172,0.83249,0.83584,0.84201,0.85125,0.86376,0.87975,0.89935,0.92263,0.949 59,0.9801;0.83587,0.84345,0.85631,0.87466,0.89867,0.9284,0.96377,1.0045,1.0502,1.1,1.1529;0.84286,0.86013,0.88537,0.91865,0.95985,1.0086,1.0642,1.1253,1.1904,1.257,1.3
19、222;0.85268,0.88251,0.92286,0.97346,1.0336,1.1019,1.1764,1.254,1.3308,1.4017,1.4605;0.86532,0.91049,0.96847,1.0383,1.118,1.2046,1.2937,1.3793,1.4539,1.5086,1.5335;0.88078,0.94396,1.0217,1.1118,1.2102,1.311,1.4063,1.4859,1.5377,1.5484,1.5052;0.89904,0.98276,1.082,1.1922,1.3061,1.4138,1.5021,1.5555,1.
20、5573,1.4915,1.346;0.92006,1.0266,1.1482,1.2768,1.4005,1.5034,1.5661,1.5678,1.4889,1.3156,1.0454;0.94381,1.0752,1.2191,1.3624,1.4866,1.5684,1.5821,1.5032,1.315,1.0155,0.62477;0.97023,1.1279,1.2929,1.4448,1.5564,1.5964,1.5341,1.3473,1.0321,0.61268,0.14763;>> x0=0.0:0.1:1; y0=x0; z=z'S=csapi(
21、x0,y0,z); fnplt(S)figure; S1=spapi(5,5,x0,y0,z); fnplt(S1)>> S1x=fnder(S1,0,1); fnplt(S1x)figure; S1y=fnder(S1,0,1); fnplt(S1y)6、重新考慮習(xí)題 3 中給出的數(shù)據(jù),試考慮用多項(xiàng)式插值的方法對其數(shù)據(jù)進(jìn)行逼近,并選 擇一個(gè)能較好擬合原數(shù)據(jù)的多項(xiàng)式階次?!厩蠼狻靠梢赃x擇不同的多項(xiàng)式階次,例如選擇 3,5,7,9,11 ,則可以對其進(jìn)行多項(xiàng)式擬 合,并繪制出曲線。>> x=-2,-1.7,-1.4,-1.1,-0.8,-0.5,-0.2,0.1,0.4,
22、0.7,1,1.3,.;y=0.10289,0.11741,0.13158,0.14483,0.15656,0.16622,0.17332,.0.1775,0.17853,0.17635,0.17109,0.16302,0.15255,0.1402,.0.12655,0.11219,0.09768,0.08353,0.07019,0.05786,0.04687,.0.03729,0.02914,0.02236;x0=-2:0.02:4.9;p3=polyfit(x,y,3); y3=polyval(p3,x0);p5=polyfit(x,y,5); y5=polyval(p5,x0);p7=p
23、olyfit(x,y,7); y7=polyval(p7,x0);p9=polyfit(x,y,9); y9=polyval(p9,x0);pl 1= polyfit(x,y,11); y1仁polyval(p11,xO);plot(x0,y3; y5; y7; y9; y11)從擬合的結(jié)果可以發(fā)現(xiàn),選擇5次多項(xiàng)式就能較好地?cái)M合原始數(shù)據(jù)7、假設(shè)習(xí)題3中給出的數(shù)據(jù)滿足原型y(x)2/2 2試用最小二乘法求出的值,并用得出的函數(shù)將函數(shù)曲線繪制出來,觀察擬合效果。【求解】令314y(x)1則可以將原型函數(shù)寫成1(x a )2/ 2a22這時(shí)可以寫出原型函數(shù)為>> f=in li ne(&
24、#39;exp(-(x-a(1)A2/2/a (2) A2)/(sqrt(2*pi)*a(2)','a','x');由原型函數(shù)則可以用下面的語句擬合出待定參數(shù)31,32,。這樣,擬合曲線得出的擬合效果是滿意的。>> x=-2,-1.7,-1.4,-1.1,-0.8,-0.5,-0.2,0.1,0.4,0.7,1,1.3,;y=0.10289,0.11741,0.13158,0.14483,0.15656,0.16622,0.17332,.0.1775,0.17853,0.17635,0.17109,0.16302,0.15255,0.1402
25、,.0.12655,0.11219,0.09768,0.08353,0.07019,0.05786,0.04687,.0.03729,0.02914,0.02236;a=lsqcurvefit(f,1,1,x,y)a =0.34605753554886 2.23400202798747>> x0=-2:0.02:5; y0=f(a,x0);plot(x0,y0,x,y,'o')8、假設(shè)習(xí)題 4中數(shù)據(jù)的原型函數(shù)為 z(x,y) asin(x2 y) b cos( y 2x ) cx2 dxy e ,試用最小二乘方法識(shí)別出a,b,c,d,e的數(shù)值?!厩蠼狻坑孟旅娴恼Z句可
26、以用最小二乘的得出>> x,y=meshgrid(0.1:0.1:1.1);z=0.83041,0.82727,0.82406,0.82098,0.81824,0.8161,0.81481,0.81463,0.81579,0.81 853,0.82304;0.83172,0.83249,0.83584,0.84201,0.85125,0.86376,0.87975,0.89935,0.92263,0.949 59,0.9801;0.83587,0.84345,0.85631,0.87466,0.89867,0.9284,0.96377,1.0045,1.0502,1.1,1.152
27、 9;0.84286,0.86013,0.88537,0.91865,0.95985,1.0086,1.0642,1.1253,1.1904,1.257,1.32 22;0.85268,0.88251,0.92286,0.97346,1.0336,1.1019,1.1764,1.254,1.3308,1.4017,1.460 5;0.86532,0.91049,0.96847,1.0383,1.118,1.2046,1.2937,1.3793,1.4539,1.5086,1.5335;0.88078,0.94396,1.0217,1.1118,1.2102,1.311,1.4063,1.4859,1.5377,1.5484,1.5052;0.89904,0.98276,1.082,1.1922,1.3061,1.4138,1.5021,1.5555,1.5573,1.4915,1.346;0.
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024年光伏發(fā)電設(shè)備維修與保養(yǎng)合同
- 保安隊(duì)長聘用合同格式
- 上市公司總部購房合同范本
- 臨時(shí)演員參演真人秀合同
- 2024廣東省禽、畜委托養(yǎng)殖合同
- 2024年城市供水特許經(jīng)營權(quán)合同協(xié)議
- 水利水電工程施工合同范本
- 體育場館鋼架雨棚安裝合同
- 鍛煉語言表達(dá)課程設(shè)計(jì)
- 鋼結(jié)構(gòu)課程設(shè)計(jì)豪式
- 渠道管理PPT(第3版)完整全套教學(xué)課件
- 精益工廠布局及精益物流規(guī)劃課件
- 《新時(shí)代勞動(dòng)教育》-02新時(shí)代勞動(dòng)價(jià)值觀課件
- 2023年口腔醫(yī)學(xué)期末復(fù)習(xí)-牙周病學(xué)(口腔醫(yī)學(xué))考試歷年真題薈萃帶答案
- 多元智能測試題及多元智能測試量表
- 【典型案例】長江流域浙江的歷史發(fā)展:人民群眾是社會(huì)物質(zhì)財(cái)富的創(chuàng)造者
- 完整版平安基礎(chǔ)性向測試智商測試題及問題詳解
- 《疾病與人類健康》
- 車輛技術(shù)檔案范本(一車一檔)
- 人工智能智慧樹知到答案章節(jié)測試2023年復(fù)旦大學(xué)
- 初中物理知識(shí)點(diǎn)手冊大全(挖空+答案)
評論
0/150
提交評論