(完整word版)計(jì)算方法第三次上機(jī)作業(yè)_第1頁
(完整word版)計(jì)算方法第三次上機(jī)作業(yè)_第2頁
(完整word版)計(jì)算方法第三次上機(jī)作業(yè)_第3頁
(完整word版)計(jì)算方法第三次上機(jī)作業(yè)_第4頁
(完整word版)計(jì)算方法第三次上機(jī)作業(yè)_第5頁
已閱讀5頁,還剩3頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、計(jì)算方法第三次上機(jī)作業(yè)gegebao摘要:程序基于 MATLAB包括問題陳述、算法與程序、結(jié)果與分析、討論四個部分。一、問題陳述考慮如下的Dirichlet問題:-? + ?= ? 以?< 1?二?其中r是正方形區(qū)域的邊界。類似模型問題,得到差分方程:?2(1 +?4)1 ?2?,? 4(?+1,?+ ?-1'?+ ?,?+ ?,?=7 7?77?1,2 , .?1?,0= ?,0 ?= ?,?,?= ?,? 0,1,2,?,?= ?,? 0,1,2,n按照“自然順序排列”,得到系數(shù)矩陣為? ?A = ? ?'? ? ? ?其中B=- 4 ? I為n-1階單位矩陣,S為對

2、角元均為1+hA2/4、次對角元均為-1/4的n-1階對稱三對角矩陣。對f=sin (xy), ?= ?+ ?,n=20,用共軛梯度法求解 差分方程的解,要求有4位有效數(shù)字。算法與程序1、系數(shù)矩陣A的乘法Amulti (m)A是大型稀疏矩陣,如果用傳統(tǒng)的方法存儲,將會造成空間的極大浪費(fèi); 而且在矩陣與矩陣的乘法中效率也不高。在整個求解過程中,A始終以與列向量相乘的形式出現(xiàn),我們考慮可以將A與列向量的乘法寫成一個函數(shù),而不再單獨(dú) 存儲A。而且這個矩陣本身具有的周期性,使函數(shù)的實(shí)現(xiàn)更為簡便。輸入一個列向量 m,輸出n=A*m的結(jié)果。fun cti on n = Amulti( m )h=1/20;

3、for i=1:19*19n(i)=m(i)*(1+h*h/4);if (mod(i,19)=1) n(i)=n(i)+m(i-1)*(-1/4);if (mod(i,19)=0) n(i)=n(i)+m(i+1)*(-1/4);if (i>19) n(i)=n(i)+m(i-19)*(-1/4);%A(i,i)=1+h*h/4end %A(i,i-1)=-1/4end %A(i,i+1)=-1/4end%A(i,i-19)=-1/4if (i<19*18+1) n(i)=n(i)+m(i+19)*(-1/4);end%A(i,i+19)=-1/4end end2、主程序 Diri

4、chlet.m需要解方程 Ax=b。 A 由函數(shù) Amulti ()代替, b 則由一個二重循環(huán)產(chǎn)生。將x的初值賦為b,開始迭代,迭代一共進(jìn)行19*19次。最終得到解x和誤差r。 為了將解以更直觀的形式表現(xiàn)出來, 程序還將一維矩陣x轉(zhuǎn)化為二維矩陣,并加 入邊界值,最后輸出一個三維的圖像。%首先生成 b ;for i=1:19for j=1:19b(i-1)*19+j)=sin(i/20*j/20)*1/1600 ;if (i=1) b(i-1)*19+j)= b(i-1)*19+j)+j*j/1600;endif (i=19) b(i-1)*19+j)= b(i-1)*19+j)+j*j/16

5、00+1/4;endif (j=1) b(i-1)*19+j)= b(i-1)*19+j)+i*i/1600;endif (j=19) b(i-1)*19+j)= b(i-1)*19+j)+i*i/1600+1/4;endend end %調(diào)整初始條件 x=b;r=b-Amulti(x); k=0; %開始迭代,共進(jìn)行 19*19 次 while (k=19*19)k=k+1;if (k=1)p=r;else q=r*r'/(r0*r0'); p=r+p0*q'enda=r*r'/(Amulti(p)*p'); x=x+p*a'r0=r;r=r-

6、Amulti(p)*a'p0=p;end喲將一維的解x轉(zhuǎn)化成二維的X,并加入邊界條件 for i=0:20for j=0:20if (i=0) X(i+1,j+1)=j*j/400;if (i=20) X(i+1,j+1)=j*j/400+1;if (j=0) X(i+1,j+1)=i*i/400;%k計(jì)步器,記錄迭代進(jìn)行的次數(shù)elseelseelseelseif (j=20) X(i+1,j+1)=i*i/400+1;X(i+1,j+1)=x(i-1)*19+j);endendendendendend%輸岀三維圖像surf(0:1/20:1,0:1/20:1,X);end三、結(jié)果與分

7、析解 x=(每列19個,保留四位小數(shù))0.02140.04040.06130.08520.11250.14360.17870.21780.26110.30850.04040.06880.09730.12720.15910.19360.23110.27190.31600.36360.06130.09730.13220.16730.20330.24110.28090.32320.36810.41580.08520.12720.16730.20670.24640.28690.32880.37250.41820.46610.11250.15910.20330.24640.28900.33190.375

8、60.42050.46690.51500.14360.19360.24110.28690.33190.37670.42190.46780.51480.56310.17870.23110.28090.32880.37560.42190.46820.51500.56250.61090.21780.27190.32320.37250.42050.46780.51500.56230.61020.65880.26110.31600.36810.41820.46690.51480.56250.61020.65830.70700.30850.36360.41580.46610.51500.56310.610

9、90.65880.70700.75570.36030.41470.46640.51630.56480.61270.66030.70810.75630.80510.41630.46930.51990.56870.61650.66370.71080.75830.80630.85510.47650.52740.57610.62330.66980.71590.76230.80920.85690.90570.54090.58890.63500.68000.72460.76930.81450.86070.90800.95660.60930.65360.69640.73850.78070.82350.867

10、30.91240.95921.00770.68170.72130.75990.79850.83770.87810.92020.96411.01021.05860.75780.79160.82510.85940.89510.93270.97271.01531.06061.10880.83720.86380.89120.92050.95220.98681.02441.06541.10991.15780.91930.93710.95750.98111.00831.03941.07461.11391.15741.20510.36030.41630.47650.54090.60930.68170.757

11、80.83720.91930.41470.46930.52740.58890.65360.72130.79160.86380.93710.46640.51990.57610.63500.69640.75990.82510.89120.95750.51630.56870.62330.68000.73850.79850.85940.92050.98110.56480.61650.66980.72460.78070.83770.89510.95221.00830.61270.66370.71590.76930.82350.87810.93270.98681.03940.66030.71080.762

12、30.81450.86730.92020.97271.02441.07460.70810.75830.80920.86070.91240.96411.01531.06541.11390.75630.80630.85690.90800.95921.01021.06061.10991.15740.80510.85510.90570.95661.00771.05861.10881.15781.20510.85450.90470.95551.00671.05811.10931.15991.20941.25710.90470.95521.00641.05821.11031.16231.21391.264

13、41.31340.95551.00641.05831.11091.16421.21761.27071.32301.37391.00671.05821.11091.16491.21961.27491.33021.38501.43851.05811.11031.16421.21961.27641.33411.39231.45021.50731.10931.16231.21761.27491.33411.39481.45641.51841.58001.15991.21391.27071.33021.39231.45641.52231.58931.65641.20941.26441.32301.385

14、01.45021.51841.58931.66211.73621.25711.31341.37391.43851.50731.58001.65641.73621.8187誤差r=(每列十九個,用科學(xué)計(jì)數(shù)法表示)6.41E-897.28E-887.44E-882.86E-88-1.08E-877.43E-88-6.53E-884.42E-887.25E-888.41E-884.66E-882.01E-878.76E-882.80E-885.11E-88-1.56E-878.58E-88-1.21E-876.92E-885.03E-881.70E-879.25E-891.90E-871.14E-8

15、7-1.22E-879.57E-88-2.46E-874.08E-88-3.63E-881.02E-87-2.61E-891.56E-871.36E-87-1.59E-882.84E-89-1.86E-873.48E-88-1.21E-871.05E-871.96E-878.97E-88-1.71E-878.28E-88-1.41E-87-2.80E-87-4.75E-88-2.77E-871.21E-88-4.22E-887.48E-88-4.40E-888.13E-88-8.29E-88-6.58E-88-7.37E-88-2.47E-87-1.49E-87-8.15E-882.51E-8

16、98.04E-885.17E-88-5.24E-88-8.68E-88-7.01E-88-3.34E-87-1.20E-87-2.42E-87-1.25E-877.48E-881.65E-88-4.88E-89-4.90E-88-4.08E-88-1.22E-87-2.52E-88-1.41E-87-7.17E-882.37E-88-1.89E-881.73E-877.68E-885.52E-88-8.51E-881.75E-87-1.22E-871.35E-87-2.43E-884.65E-888.28E-88-6.47E-881.13E-874.05E-881.91E-872.55E-88

17、1.85E-87-4.76E-885.54E-881.67E-87-9.87E-882.13E-87-1.38E-884.86E-902.69E-891.23E-877.69E-891.40E-878.64E-882.76E-886.30E-88-7.61E-88-7.63E-881.24E-88-1.30E-879.23E-88-6.41E-898.62E-881.00E-876.79E-88-3.45E-88-7.16E-88-5.88E-89-1.77E-876.09E-89-1.36E-871.09E-87-5.21E-884.01E-88-1.00E-87-1.93E-88-1.61

18、E-87-1.80E-876.28E-88-2.62E-871.15E-87-2.79E-882.03E-871.00E-87-2.25E-88-1.13E-87-1.48E-87-5.24E-88-2.30E-871.13E-87-1.85E-871.71E-871.04E-876.20E-88-2.14E-88-5.62E-88-1.35E-87-2.09E-881.16E-87-3.01E-881.43E-871.22E-871.60E-872.01E-877.61E-883.32E-89-4.81E-88-1.11E-88-1.57E-881.15E-875.79E-881.68E-8

19、72.26E-876.18E-883.09E-885.53E-88-1.58E-87-5.27E-881.02E-873.77E-883.96E-881.61E-876.66E-882.11E-872.00E-893.79E-888.16E-89-1.52E-885.76E-883.20E-888.93E-886.31E-886.00E-88-1.13E-881.38E-881.18E-87-8.34E-889.06E-88-1.12E-873.72E-88-1.69E-87-2.73E-88-6.88E-888.53E-88-4.53E-881.03E-88-9.00E-881.28E-87

20、-2.38E-871.01E-87-2.17E-871.31E-87-8.02E-881.45E-873.53E-881.36E-87-9.13E-881.79E-88-1.97E-871.32E-88-4.60E-881.22E-87-4.76E-889.60E-88-3.56E-881.02E-87-1.62E-87-1.20E-88-1.15E-876.05E-895.26E-881.29E-874.98E-886.92E-888.26E-886.56E-891.51E-87-8.20E-881.88E-871.15E-878.68E-881.14E-876.11E-883.09E-88

21、1.03E-87-5.30E-892.42E-875.61E-882.13E-879.96E-886.13E-881.33E-871.46E-87-5.33E-882.37E-87-6.74E-882.09E-871.64E-871.20E-871.19E-87-6.21E-896.21E-882.06E-88-1.09E-878.82E-887.39E-881.22E-881.60E-87-7.79E-884.60E-88-3.39E-88-6.62E-88-1.21E-87-5.15E-89-1.38E-871.70E-87-1.11E-871.95E-87-8.03E-88-5.57E-

22、88-1.24E-87-1.51E-87-1.82E-877.86E-88-2.32E-871.54E-87-9.31E-88-3.84E-88-8.42E-88-5.33E-88-6.79E-881.25E-88-2.21E-871.09E-87-2.20E-878.13E-88-4.68E-88-7.55E-881.62E-87-1.05E-871.30E-871.98E-88-1.45E-874.79E-88-1.04E-87-6.00E-881.30E-87-7.56E-882.56E-871.65E-889.91E-88-1.70E-881.89E-88-9.99E-89-2.28E

23、-89-1.35E-873.02E-874.81E-892.46E-87-1.92E-878.64E-89-1.60E-87-7.10E-88-5.50E-887.66E-88-1.72E-882.37E-87-6.10E-881.09E-87-2.10E-87-4.44E-88-1.99E-87-1.75E-873.27E-88-2.55E-88-9.90E-88-1.45E-88-2.21E-87-1.30E-87-1.96E-87-4.04E-887.88E-88-1.77E-875.18E-88-1.05E-87-5.40E-88-1.23E-87-2.31E-87-8.45E-88-

24、2.04E-87-1.64E-877.36E-88-7.94E-888.56E-88-1.86E-87-1.44E-87-1.31E-87-8.95E-88-4.80E-881.08E-87-1.20E-871.89E-88-1.68E-87-2.57E-88-8.38E-88-7.78E-88-4.98E-88-3.53E-88將x轉(zhuǎn)化為二維矩陣X=(每列二十個,保留四位小數(shù))0.00000.00250.01000.02250.04000.06250.09000.12250.16000.20250.00250.02140.04040.06130.08520.11250.14360.17870

25、.21780.26110.01000.04040.06880.09730.12720.15910.19360.23110.27190.31600.02250.06130.09730.13220.16730.20330.24110.28090.32320.36810.04000.08520.12720.16730.20670.24640.28690.32880.37250.41820.06250.11250.15910.20330.24640.28900.33190.37560.42050.46690.09000.14360.19360.24110.28690.33190.37670.42190

26、.46780.51480.12250.17870.23110.28090.32880.37560.42190.46820.51500.56250.16000.21780.27190.32320.37250.42050.46780.51500.56230.61020.20250.26110.31600.36810.41820.46690.51480.56250.61020.65830.25000.30850.36360.41580.46610.51500.56310.61090.65880.70700.30250.36030.41470.46640.51630.56480.61270.66030

27、.70810.75630.36000.41630.46930.51990.56870.61650.66370.71080.75830.80630.42250.47650.52740.57610.62330.66980.71590.76230.80920.85690.49000.54090.58890.63500.68000.72460.76930.81450.86070.90800.56250.60930.65360.69640.73850.78070.82350.86730.91240.95920.64000.68170.72130.75990.79850.83770.87810.92020

28、.96411.01020.72250.75780.79160.82510.85940.89510.93270.97271.01531.06060.81000.83720.86380.89120.92050.95220.98681.02441.06541.10990.90250.91930.93710.95750.98111.00831.03941.07461.11391.15741.00001.00251.01001.02251.04001.06251.09001.12251.16001.20250.25000.30250.36000.42250.49000.56250.64000.72250

29、.81000.90251.00000.30850.36030.41630.47650.54090.60930.68170.75780.83720.91931.00250.36360.41470.46930.52740.58890.65360.72130.79160.86380.93711.01000.41580.46640.51990.57610.63500.69640.75990.82510.89120.95751.02250.46610.51630.56870.62330.68000.73850.79850.85940.92050.98111.04000.51500.56480.61650

30、.66980.72460.78070.83770.89510.95221.00831.06250.56310.61270.66370.71590.76930.82350.87810.93270.98681.03941.09000.61090.66030.71080.76230.81450.86730.92020.97271.02441.07461.12250.65880.70810.75830.80920.86070.91240.96411.01531.06541.11391.16000.70700.75630.80630.85690.90800.95921.01021.06061.10991.15741.20250.75570.80510.85510.90570.95661.00771.05861.10881.15781.20511.25000.80510.85450.90470.95551.00671.05811.10931.15991.20941.25711.30250.85510.90470.95521.00641.05821.11031.16231.21391.26441.31341.36000.90570.95551.00641.05831.11091.

溫馨提示

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

評論

0/150

提交評論