




版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
1、 數(shù)值分析上機報告第一章一、題目精確值為。1) 編制按從大到小的順序,計算sn的通用程序。2) 編制按從小到大的順序,計算sn的通用程序。3) 按兩種順序分別計算,并指出有效位數(shù)。(編制程序時用單精度)4) 通過本次上機題,你明白了什么?二、通用程序clearn=input('please input an n (n>1):');accuratevalue=single(0-1/(n+1)-1/n+3/2)/2);sn1=single(0);for a=2:n; sn1=sn1+1/(a2-1);endsn2=single(0);for a=2:n; sn2=sn2+1/
2、(n-a+2)2-1);endfprintf('the value of sn using different algorithms (n=%d)n',n);disp('_')fprintf('accurate calculation %fn',accuratevalue);fprintf('caculate from large to small %fn',sn1);fprintf('caculate from small to large %fn',sn2);disp('_')三、求解結果ple
3、ase input an n (n>1):102the value of sn using different algorithms (n=100)_accurate calculation 0.740049caculate from large to small 0.740049caculate from small to large 0.740050_please input an n (n>1):104the value of sn using different algorithms (n=10000)_accurate calculation 0.749900cacula
4、te from large to small 0.749852caculate from small to large 0.749900_please input an n (n>1):106the value of sn using different algorithms (n=1000000)_accurate calculation 0.749999caculate from large to small 0.749852caculate from small to large 0.749999_ 四、結果分析 有效位數(shù) n 順序 100 10000 1000000從大到小633
5、從小到大566可以得出,算法對誤差的傳播又一定的影響,在計算時選一種好的算法可以使結果更為精確。從以上的結果可以看到從大到小的順序導致大數(shù)吃小數(shù)的現(xiàn)象,容易產(chǎn)生較大的誤差,求和運算從小數(shù)到大數(shù)算所得到的結果才比較準確。 第二章一、題目(1)給定初值及容許誤差,編制牛頓法解方程f(x)=0的通用程序。(2)給定方程,易知其有三個根a) 由牛頓方法的局部收斂性可知存在當時,newton迭代序列收斂于根x2*。試確定盡可能大的。b)試取若干初始值,觀察當時newton序列的收斂性以及收斂于哪一個根。(3)通過本上機題,你明白了什么?二、通用程序文件search.m%尋找最大的delta值%clear
6、%flag=1;k=1;x0=0;while flag=1 delta=k*10-6; x0=delta; k=k+1; m=0; flag1=1; while flag1=1 && m<=103 x1=x0-fx(x0)/dfx(x0); if abs(x1-x0)<10-6 flag1=0; end m=m+1; x0=x1; end if flag1=1|abs(x0)>=10-6 flag=0; endendfprintf('the maximun delta is %fn',delta); 文件fx.m% 定義函數(shù)f(x)functi
7、on fx=fx(x) fx=x3/3-x;文件dfx.m% 定義導函數(shù)df(x)function fx=dfx(x) fx=x2-1;文件newton.m% newton法求方程的根%clear%ef=10-6; %給定容許誤差10-6k=0;x0=input('please input initial value xo:');disp('k xk');fprintf('0 %fn',x0); flag=1;while flag=1 && k<=103 x1=x0-fx(x0)/dfx(x0); if abs(x1-x0)
8、<ef flag=0; end k=k+1; x0=x1;fprintf('%d %fn',k,x0); end 三、求解結果1.運行search.m文件結果為: the maximum delta is 0.774597即得最大的為0.774597,newton迭代序列收斂于根=0的最大區(qū)間為(-0.774597,0.774597)。2.運行newton.m文件在區(qū)間上各輸入若干個數(shù),計算結果如下:區(qū)間上取-1000,-100,-50,-30,-10,-8,-7,-5,-3,-1.513 -1.732051please input initial value xo:-3
9、0k xk0 -30.0000001 -20.0222472 -13.3815443 -8.9711294 -6.0560005 -4.1505036 -2.9375247 -2.2150468 -1.8547149 -1.74323610 -1.73215811 -1.73205112 -1.732051please input initial value xo:-10k xk0 -10.0000001 -6.7340072 -4.5905703 -3.2128404 -2.3716535 -1.9229816 -1.7571757 -1.7325808 -1.7320519 -1.7320
10、51please input initial value xo:-10000k xk0 -10000.0000001 -6666.6667332 -4444.4445893 -2962.9632094 -1975.3090315 -1316.8730256 -877.9158567 -585.2779978 -390.1864709 -260.12602210 -173.41991111 -115.61711812 -77.08384513 -51.39788014 -34.27822915 -22.87161816 -15.27694917 -10.22845918 -6.88478019
11、-4.68877220 -3.27480721 -2.40771422 -1.93975023 -1.76125924 -1.73276225 -1.73205126 -1.732051please input initial value xo:-100k xk0 -100.0000001 -66.6733342 -44.4588913 -29.6542634 -19.7920165 -13.2284476 -8.8696517 -5.9892318 -4.1073249 -2.91075510 -2.20018911 -1.84868712 -1.74223513 -1.73213914 -
12、1.73205115 -1.732051please input initial value xo:-50k xk0 -50.0000001 -33.3466722 -22.2511253 -14.8641054 -9.9544585 -6.7039606 -4.5710137 -3.2005208 -2.3645159 -1.91970310 -1.75640511 -1.73254812 -1.732051please input initial value xo:-3k xk0 -3.0000001 -2.2500002 -1.8692313 -1.7458104 -1.7322125
13、-1.7320516 -1.732051please input initial value xo:-1.5k xk0 -1.5000001 -1.8000002 -1.7357143 -1.7320624 -1.7320515 -1.732051please input initial value xo:-8k xk0 -8.0000001 -5.4179892 -3.7393793 -2.6849344 -2.0782465 -1.8029286 -1.7360237 -1.7320648 -1.7320519 -1.732051please input initial value xo:
14、-7k xk0 -7.0000001 -4.7638892 -3.3223183 -2.4355334 -1.9529155 -1.7646306 -1.7329317 -1.7320518 -1.732051please input initial value xo:-5k xk0 -5.0000001 -3.4722222 -2.5241803 -1.9960684 -1.7766185 -1.7336746 -1.7320537 -1.7320518 -1.732051結果顯示,以上初值迭代序列均收斂于-1.732051,即根。在區(qū)間即區(qū)間(-1,-0.774597)上取-0.77459
15、8,-0.8,-0.85,-0.9,-0.99,計算結果如下:please input initial value xo:-0.774598k xk0 -0.7745981 0.7746052 -0.7746453 0.7748844 -0.7763245 0.7850496 -0.8406417 1.3501878 1.9938309 1.77596310 1.73362811 1.73205312 1.73205113 1.732051please input initial value xo:-0.8k xk0 -0.8000001 0.9481482 -5.6253703 -3.872
16、6254 -2.7661975 -2.1213676 -1.8182927 -1.7378228 -1.7320799 -1.73205110 -1.732051please input initial value xo:0.85k xk0 0.8500001 -1.4753752 -1.8194443 -1.7379694 -1.7320815 -1.7320516 -1.732051please input initial value xo:-0.9k xk0 -0.9000001 2.5578952 2.0129153 1.7816624 1.7340495 1.7320546 1.73
17、20517 1.732051please input initial value xo:-0.99k xk0 -0.9900001 32.5058292 21.6910813 14.4915214 9.7072385 6.5409066 4.4649667 3.1338408 2.3260759 1.90230310 1.75247811 1.73240312 1.73205113 1.732051計算結果顯示,迭代序列局部收斂于-1.732051,即根,局部收斂于1.730251,即根。在區(qū)間即區(qū)間(-0.774597,0.774597)上,由search.m的運行過程表明,在整個區(qū)間上均收
18、斂于0,即根。please input initial value xo:0.774598k xk0 0.7745981 -0.7746052 0.7746453 -0.7748844 0.7763245 -0.7850496 0.8406417 -1.3501878 -1.9938309 -1.77596310 -1.73362811 -1.73205312 -1.73205113 -1.732051please input initial value xo:0.8k xk0 0.8000001 -0.9481482 5.6253703 3.8726254 2.7661975 2.12136
19、76 1.8182927 1.7378228 1.7320799 1.73205110 1.732051please input initial value xo:0.85k xk0 0.8500001 -1.4753752 -1.8194443 -1.7379694 -1.7320815 -1.7320516 -1.732051please input initial value xo:0.9k xk0 0.9000001 -2.5578952 -2.0129153 -1.7816624 -1.7340495 -1.7320546 -1.7320517 -1.732051please inp
20、ut initial value xo:0.99k xk0 0.9900001 -32.5058292 -21.6910813 -14.4915214 -9.7072385 -6.5409066 -4.4649667 -3.1338408 -2.3260759 -1.90230310 -1.75247811 -1.73240312 -1.73205113 -1.732051在區(qū)間即區(qū)間(0.774597,1)上取0.774598,0.8,0.85,0.9,0.99,計算結果如下:計算結果顯示,迭代序列局部收斂于-1.732051,即根,局部收斂于1.730251,即根。please input
21、 initial value xo:4k xk0 4.0000001 2.8444442 2.1637243 1.8342814 1.7400075 1.7321056 1.7320517 1.732051please input initial value xo:3k xk0 3.0000001 2.2500002 1.8692313 1.7458104 1.7322125 1.7320516 1.732051please input initial value xo:1.5k xk0 1.5000001 1.8000002 1.7357143 1.7320624 1.7320515 1.7
22、32051區(qū)間上取100,60,20,10,7,6,4,3,1.5,計算結果如下:6 2.2136057 1.8541268 1.7431369 1.73215610 1.73205111 1.732051please input initial value xo:10k xk0 10.0000001 6.7340072 4.5905703 3.2128404 2.3716535 1.9229816 1.7571757 1.7325808 1.7320519 1.732051please input initial value xo:7k xk0 7.0000001 4.7638892 3.3
23、223183 2.4355334 1.9529155 1.7646306 1.7329317 1.7320518 1.732051please input initial value xo:6k xk0 6.0000001 4.1142862 2.9150683 2.2025784 1.8496505 1.7423926 1.7321427 1.7320518 1.732051please input initial value xo:100k xk0 100.0000001 66.6733342 44.4588913 29.6542634 19.7920165 13.2284476 8.86
24、96517 5.9892318 4.1073249 2.91075510 2.20018911 1.84868712 1.74223513 1.73213914 1.73205115 1.732051please input initial value xo:60k xk0 60.0000001 40.0111142 26.6907493 17.8188454 11.9167625 8.0008486 5.4185467 3.7397368 2.6851519 2.07836010 1.80296711 1.73602712 1.73206413 1.73205114 1.732051plea
25、se input initial value xo:20k xk0 20.0000001 13.3667502 8.9613233 6.0495474 4.146328結果顯示,以上初值迭代序列均收斂于1.732051,即根。綜上所述:(-,-1)區(qū)間收斂于-1.73205,(-1,)區(qū)間局部收斂于1.73205,局部收斂于-1.73205,(-,)區(qū)間收斂于0,(,1)區(qū)間類似于(-1,)區(qū)間,(1,)收斂于1.73205。通過本上機題,明白了對于多根方程,newton法求方程根時,迭代序列收斂于某一個根有一定的區(qū)間限制,在一個區(qū)間上,可能會局部收斂于不同的根。第三章一、題目列主元gauss
26、消去法對于某電路的分析,歸結為求解線性方程組。其中(1) 編制解n階線性方程組的列主元高斯消去法的通用程序;(2) 用所編程序線性方程組,并打印出解向量,保留5位有效數(shù);二、通用程序% 列主元gauss消去法求解線性方程組%參數(shù)輸入n=input('please input the order of matrix a: n='); %輸入線性方程組階數(shù)nb=zeros(1,n);a=input('input matrix a (such as a 2 order matrix:1 2;3,4) :');b(1,:)=input('input the co
27、lumn vector b:'); %輸入行向量bb=b' c=a,b; %得到增廣矩陣%列主元消去得上三角矩陣for i=1:n-1 maximum,index=max(abs(c(i:n,i); index=index+i-1; t=c(index,:); c(index,:)=c(i,:); c(i,:)=t; for k=i+1:n %列主元消去 if c(k,i)=0 c(k,:)=c(k,:)-c(k,i)/c(i,i)*c(i,:); end endend% 回代求解 %x=zeros(n,1);x(n)=c(n,n+1)/c(n,n);for i=n-1:-1:
28、1 x(i)=(c(i,n+1)-c(i,i+1:n)*x(i+1:n,1)/c(i,i);enda=c(1:n,1:n); %消元后得到的上三角矩陣disp('the upper teianguular matrix is:')for k=1:n fprintf('%f ',a(k,:); fprintf('n');enddisp('solution of the equations:');fprintf('%.5gn',x); %以5位有效數(shù)字輸出結果 please input the order of mat
29、rix a: n=4input matrix a (such as a 2 order matrix:1 2;3,4)1 2 1 -22 5 3 -2-2 -2 3 51 3 2 3input the column vector b:4 7 -1 02.000000 5.000000 3.000000 -2.000000 0.000000 3.000000 6.000000 3.000000 0.000000 0.000000 0.500000 -0.500000 0.000000 0.000000 0.000000 3.000000 solution of the equations:2-1
30、2-1以教材第123頁習題16驗證通用程序的正確性。執(zhí)行程序,輸入系數(shù)矩陣a和列向量b,結果如下:結果與精確解完全一致。三、求解結果執(zhí)行程序,輸入矩陣a(即題中的矩陣r)和列向量b(即題中的v),得如下結果:please input the order of matrix a: n=9input matrix a (such as a 2 order matrix:1 2;3,4):31 -13 0 0 0 -10 0 0 0-13 35 -9 0 -11 0 0 0 00 -9 31 -10 0 0 0 0 00 0 -10 79 -30 0 0 0 -90 0 0 -30 57 -7 0 -5 00 0 0 0 -7 47 -30 0 00 0 0 0 0 -30 41 0 00 0 0 0 -5 0 0 27 -20 0 0 -9 0 0 0 -2 29input the column vector b:-15 27 -23 0 -20 12 -7 7 1031.000000 -13.000000 0.000000 0.000000 0.000000 -10.000000 0.000000 0.000000 0.000000 0.000000 29.548387 -9.000000 0.000000 -11.000000 -4.193548 0.000000 0.000
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 國際產(chǎn)品授權分銷合同
- 辦公家具采購合同一
- 商品買賣合同「樣本」
- 商業(yè)地產(chǎn)買賣合同模板范文
- 公司設立投資合作合同范本
- 礦山棄渣處理合同范本
- 消防及安全整改合同履行細則
- 校企合作合同新范本
- 土地使用權出讓合同及物業(yè)銷售細則
- 躉船結構培訓課件
- 2025年黑龍江民族職業(yè)學院單招職業(yè)技能測試題庫附答案
- 年產(chǎn)60萬噸摻混肥項目可行性研究報告申請立項
- 2025年2月《公共安全視頻圖像信息系統(tǒng)管理條例》學習解讀課件
- 2025年江蘇省中職《英語》學業(yè)水平考試高頻必練考試題庫400題(含答案)
- 2025年濟寧職業(yè)技術學院高職單招語文2018-2024歷年參考題庫頻考點含答案解析
- 高三一?!吧媾c強弱關系思辨”審題立意及范文
- 2025年湖南工程職業(yè)技術學院高職單招職業(yè)適應性測試近5年??及鎱⒖碱}庫含答案解析
- 2024年七臺河職業(yè)學院高職單招數(shù)學歷年參考題庫含答案解析
- 小學數(shù)學教學中小組合作學習課件
- 2024年晉中職業(yè)技術學院單招職業(yè)技能測試題庫附答案
- 2025年茂名市高三年級第一次綜合測試(一模)物理試卷(含答案)
評論
0/150
提交評論