數(shù)值分析實(shí)驗(yàn)(6)_第1頁(yè)
數(shù)值分析實(shí)驗(yàn)(6)_第2頁(yè)
數(shù)值分析實(shí)驗(yàn)(6)_第3頁(yè)
數(shù)值分析實(shí)驗(yàn)(6)_第4頁(yè)
數(shù)值分析實(shí)驗(yàn)(6)_第5頁(yè)
已閱讀5頁(yè),還剩8頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、實(shí)驗(yàn)六 解線性方程組的迭代法 專業(yè)班級(jí):信計(jì)131班 姓名:段雨博 學(xué)號(hào):2013014907一、實(shí)驗(yàn)?zāi)康?、熟悉matlab編程。2、學(xué)習(xí)線性方程組的迭代解法的程序設(shè)計(jì)算法。二、實(shí)驗(yàn)題目1、研究解線性方程組迭代法收斂速度。A為20階五對(duì)角距陣 (1)選取不同的初始向量及右端向量b,給定迭代誤差要求,用雅可比迭代和高斯-賽德爾迭代法求解,觀察得到的序列是否收斂?若收斂,記錄迭代次數(shù),分析計(jì)算結(jié)果并得出你的結(jié)論。(2)用SOR迭代法求解上述方程組,松弛系數(shù)取1< <2的不同值,在時(shí)停止迭代。記錄迭代次數(shù),分析計(jì)算結(jié)果并得出你的結(jié)論。P211 2、給出線性方程組,其中系數(shù)矩陣Hn為希爾

2、伯特矩陣: 假設(shè)若取分別用雅可比迭代法及SOR迭代法求解,比較計(jì)算結(jié)果。三、實(shí)驗(yàn)原理與理論基礎(chǔ)1、雅可比迭代法:將線性方程組的系數(shù)矩陣分成三部分設(shè),選取M為A的對(duì)角元素部分,即選取M=D(對(duì)角矩陣),A=D-N,由得到解的雅可比迭代法其中。稱J為解的雅可比迭代法的迭代矩陣。解的雅可比迭代法的計(jì)算公式為2、高斯-塞德爾迭代法:選取分裂矩陣M為A的下三角部分,即選取,于是由的到解的高斯-塞得爾迭代法其中。稱G為解的高斯-塞得爾迭代法的迭代矩陣解的高斯-塞得爾迭代法的迭代法計(jì)算公式為3、超松弛迭代法:選取分裂矩陣M為帶參數(shù)的下三角矩陣其中為可選擇的松弛因子于是由可以構(gòu)造一個(gè)迭代法,其迭代矩陣為從而得

3、到解的逐次超松弛迭代法,簡(jiǎn)稱SOR方法解的SOR方法為其中解的SOR方法的迭代法計(jì)算公式為四、實(shí)驗(yàn)內(nèi)容1、(1)雅可比迭代法的M文件:function =yakebi(e)%ÊäÈë¾ØÕóaÓëÓÒ¶ËÏòÁ¿b¡£for i=1:20 a(i,i)=3;endfor i=3:20 for j=i-2 a(i,j)=-1/4; a(j,i)=-1/4; endendfor i=2:20 for

4、j=i-1 a(i,j)=-1/2; a(j,i)=-1/2; endendb=2.2 1.7 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.7 2.2;k=1;n=length(a);for i=1:n x(1,i)=1;%Êý×éÖÐûÓеÚ0ÐС£endwhile k>=1 for i=1:n m=0; %´Ë&#

5、178;½Ò²¿ÉÒÔÓÃifj=iÌõ¼þÅж¨Ò»Ï¡£ for j=1:(i-1) m=m+a(i,j)*x(k,j); end for j=(i+1):n m=m+a(i,j)*x(k,j); end x(k+1,i)=(b(i)-m)/a(i,i); end l=0; %Åж¨Âú×

6、ãÌõ¼þʹѭ»·Í£Ö¹µü´ú¡£ for i=1:n l=l+abs(x(k+1,i)-x(k,i); end if l<e break end k=k+1;end%Êä³öËùÓеÄxµÄÖµ¡£ x(k+1,

7、:)k (2)高斯-塞德爾迭代法的M文件:function =gaoshisaideer(e)for i=1:20 a(i,i)=3;endfor i=3:20 for j=i-2 a(i,j)=-1/4; a(j,i)=-1/4; endendfor i=2:20 for j=i-1 a(i,j)=-1/2; a(j,i)=-1/2; endendb=2.2 1.7 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.7 2.2;k=1;n=length(a);for i=1:n x(1,i)=0;%Ê

8、ý×éÖÐûÓеÚ0ÐС£endwhile k>=1 for i=1:n p=0;q=0; for j=1:(i-1) p=p+a(i,j)*x(k+1,j); end for j=(i+1):n q=q+a(i,j)*x(k,j); end x(k+1,i)=(b(i)-q-p)/a(i,i); end l=0; %Åж¨Âú×ãÌõ

9、;¼þʹѭ»·Í£Ö¹µü´ú¡£ for i=1:n l=l+abs(x(k+1,i)-x(k,i); end if l<e break end k=k+1;end%Êä³öËùÓеÄxµÄÖµ¡£ x(k+1,:)k(3)SOR方法的迭代的M文

10、件: function =caosongci(e,w)for i=1:20 a(i,i)=3;endfor i=3:20 for j=i-2 a(i,j)=-1/4; a(j,i)=-1/4; endendfor i=2:20 for j=i-1 a(i,j)=-1/2; a(j,i)=-1/2; endendb=2.2 1.7 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.7 2.2;k=1;n=length(a);for i=1:n x(1,i)=0;%Êý×é&#

11、214;ÐûÓеÚ0ÐС£endwhile k>=1 if w>=2|w<=1 'ÇëÖØÐÂÊäÈëwµÄÖµ£¬wÔÚ1Óë2Ö®¼ä' break end for i=1:n p=0;q=0; for j

12、=1:(i-1) p=p+a(i,j)*x(k+1,j); end for j=i:n q=q+a(i,j)*x(k,j); end x(k+1,i)=x(k,i)+w*(b(i)-q-p)/a(i,i); end l=0; %Åж¨Âú×ãÌõ¼þʹѭ»·Í£Ö¹µü´ú¡£ for i=1:n l=l+abs

13、(x(k+1,i)-x(k,i); end if l<e break end k=k+1;end%Êä³öËùÓеÄxµÄÖµ¡£ x(k+1,:)k 2、(1)雅可比迭代法:建立新的M文件:function n = 6; H = hilb(n); b = H * ones(n, 1); e = 0.00001; for i = 1:n if H(i, i) = = 0 '¶Ô½Ç

14、ԪΪÁ㣬²»ÄÜÇó½â' return endendx = zeros(n, 1); k = 0; kend = 10000; r = 1; while k< = kend&r>e x0 = x; for i = 1:n s = 0; for j = 1:i - 1 s = s + H(i, j) * x0(j); end for j = i + 1:n s = s + H(i, j) * x0(j

15、); end x(i) = b(i) / H(i, i) - s / H(i, i); end r = norm(x - x0, inf); k = k + 1; end if k>kend 'µü´ú²»ÊÕÁ²£¬Ê§°Ü' else 'Çó½â³É¹¦'x k end(2)SOR迭代法 建立新的M文件:functi

16、on s = unit62 (n, w); H = hilb(n); b = H * ones(n, 1); e = 0.00001; for i = 1:n if H(i, i) = = 0 '¶Ô½ÇԪΪÁ㣬²»ÄÜÇó½â' return endendx = zeros(n, 1); k = 0; kend = 10000; r = 1; while k< =

17、kend&r>e x0 = x; for i = 1:n s = 0; for j = 1:i - 1 s = s + H(i, j) * x(j); end for j = i + 1:n s = s + H(i, j) * x0(j); end x(i) = (1 - w) * x0(i) + w / H(i, i) * (b(i) - s); end r = norm(x - x0, inf); k = k + 1; end if k>kend 'µü´ú²»ÊÕÁ

18、78;£¬Ê§°Ü' else 'Çó½â³É¹¦'xk end 五、實(shí)驗(yàn)結(jié)果1、(1)雅可比迭代法:此時(shí)初值全取1;>> yakebi(0.00001)ans = Columns 1 through 4 0.97928690957815 0.97865527545592 0.99413112710292 0.99702522668084 Columns 5 through 8 0.99892294027653 0.99

19、953623723806 0.99981798692368 0.99992456206301 Columns 9 through 12 0.99996827213618 0.99998318569782 0.99998318569782 0.99996827213618 Columns 13 through 16 0.99992456206301 0.99981798692368 0.99953623723806 0.99892294027653 Columns 17 through 20 0.99702522668084 0.99413112710292 0.97865527545592 0

20、.97928690957815k = 12此時(shí)初值全取1;b=2.5 1.9 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.9 2.5;yakebi(0.00001)ans = Columns 1 through 4 1.09693565579242 1.07066544555281 1.02189792894430 1.01031973400603 Columns 5 through 8 1.00387123915809 1.00163550420902 1.00064915592407 1.0002682

21、8691766 Columns 9 through 12 1.00011377674600 1.00006071270830 1.00006071270830 1.00011377674600 Columns 13 through 16 1.00026828691766 1.00064915592407 1.00163550420902 1.00387123915809 Columns 17 through 20 1.01031973400603 1.02189792894430 1.07066544555281 1.09693565579242k = 14(2)高斯-塞德爾迭代法:此時(shí)初值全

22、取1;b=2.2 1.7 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.7 2.2;>>gaoshisaideer(0.00001)ans = Columns 1 through 4 0.97928672785055 0.97865497724617 0.99413072858837 0.99702477289046 Columns 5 through 8 0.99892247916398 0.99953582092589 0.99981765831007 0.99992433911341 Col

23、umns 9 through 12 0.99996813689365 0.99998309087521 0.99998307528667 0.99996810066011 Columns 13 through 16 0.99992430481311 0.99981764236491 0.99953582378631 0.99892249072258 Columns 17 through 20 0.99702478323251 0.99413073321783 0.97865497639848 0.97928672383457k = 9 此時(shí)初值全取1;b=2.5 1.9 1.5 1.5 1.5

24、 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.9 2.5;gaoshisaideer(0.00001)ans = Columns 1 through 4 1.09693579352931 1.07066567042013 1.02189822461772 1.01032005741270 Columns 5 through 8 1.00387154239400 1.00163574176580 1.00064930348687 1.00026835270258 Columns 9 through 12 1.000113797674

25、84 1.00006073762614 1.00006078469333 1.00011392257747 Columns 13 through 16 1.00026851424618 1.00064945546375 1.00163585410523 1.00387160976025 Columns 17 through 20 1.01032009166096 1.02189824119170 1.07066567972025 1.09693580005268k = 10(3)超松弛迭代法:>> caosongci(0.00001,1.5)ans = Columns 1 thro

26、ugh 4 0.97928701590089 0.97865490271041 0.99413026958549 0.99702487773165 Columns 5 through 8 0.99892287174441 0.99953541295914 0.99981725926558 0.99992443005231 Columns 9 through 12 0.99996769517344 0.99998266391833 0.99998297217233 0.99996765389656 Columns 13 through 16 0.99992414492584 0.99981754

27、006743 0.99953561936811 0.99892253859029 Columns 17 through 20 0.99702466465668 0.99413076724435 0.97865494383646 0.97928672836829k = 25>>caosongci(0.00001,1.4)ans = Columns 1 through 4 0.97928664567787 0.97865497276614 0.99413091195128 0.99702478812825 Columns 5 through 8 0.99892206829160 0.9

28、9953566779334 0.99981800024840 0.99992405385342 Columns 9 through 12 0.99996735159261 0.99998299267004 0.99998292835147 0.99996756954667 Columns 13 through 16 0.99992425828155 0.99981747914644 0.99953562290255 0.99892255444268 Columns 17 through 20 0.99702464632961 0.99413077876016 0.97865493945573

29、0.97928672953468k = 19>>caosongci(0.00001,1.3)ans = Columns 1 through 4 0.97928673960074 0.97865499490251 0.99413068018505 0.99702463941122 Columns 5 through 8 0.99892245408798 0.99953597158762 0.99981750927177 0.99992371086985 Columns 9 through 12 0.99996781471043 0.99998316284797 0.999982654

30、76437 0.99996760364789 Columns 13 through 16 0.99992428696880 0.99981744084318 0.99953566673332 0.99892252714720 Columns 17 through 20 0.99702466742315 0.99413076397455 0.97865494656202 0.97928672698708k = 15>>caosongci(0.00001,1.6)ans = Columns 1 through 4 0.97928734202960 0.97865524817880 0.

31、99413049485300 0.99702500134349 Columns 5 through 8 0.99892252381996 0.99953549297181 0.99981769782089 0.99992404686608 Columns 9 through 12 0.99996771015468 0.99998291173863 0.99998260667004 0.99996787506558 Columns 13 through 16 0.99992410875882 0.99981740832167 0.99953581362369 0.99892233973293 C

32、olumns 17 through 20 0.99702480955440 0.99413067446860 0.97865498570698 0.97928671447299k = 34>>caosongci(0.00001,1.7)ans = Columns 1 through 4 0.97928742815626 0.97865496966424 0.99413080915957 0.99702520913033 Columns 5 through 8 0.99892224601752 0.99953595378623 0.99981762797535 0.999923948

33、86168 Columns 9 through 12 0.99996811815082 0.99998261630139 0.99998287220233 0.99996788477464 Columns 13 through 16 0.99992400317099 0.99981765085329 0.99953559957412 0.99892254975631 Columns 17 through 20 0.99702465244167 0.99413077958034 0.97865495091184 0.97928669699158k = 47>>caosongci(0.

34、00001,1.9)ans = Columns 1 through 4 0.97928658878469 0.97865541113912 0.99413005731687 0.99702542411353 Columns 5 through 8 0.99892195024951 0.99953584672242 0.99981763368179 0.99992368182621 Columns 9 through 12 0.99996829312972 0.99998237481516 0.99998286366190 0.99996779489729 Columns 13 through

35、16 0.99992413173091 0.99981732532687 0.99953585011936 0.99892231744249 Columns 17 through 20 0.99702472708423 0.99413068810054 0.97865498609816 0.97928662270019k = 150松弛因子滿足誤差小于0.00001的次數(shù)1.1111.2121.3151.4191.5251.6341.7471.8731.91502、(1)雅可比迭代法:輸出結(jié)果為:ans = 迭代不收斂,失?。?)SOR迭代法:輸出結(jié)果為:ans = 求解成功x = 0.9993 1.0131 0.95371.03741.02960.9662k = 997ans = 0.6487當(dāng)n = 6,w = 1.25時(shí),ans = 求解成功x = 0.9992 1.0131 0.9

溫馨提示

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

評(píng)論

0/150

提交評(píng)論