東南大學(xué)數(shù)值分析資料報(bào)告上機(jī)_第1頁
東南大學(xué)數(shù)值分析資料報(bào)告上機(jī)_第2頁
已閱讀5頁,還剩27頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

第一章一、題目設(shè)S二,其精確值為1(3-丄—丄)。nj2—122NN+1j=2"編制按從大到小的順序S=1+1+......+-2,計(jì)算SN的通用程N(yùn)22—132—1N2—1序。編制按從小到大的順序S=+++,計(jì)算SN的NN2—1(N—1)2—122—1通用程序。按兩種順序分別計(jì)算S102,S104,S106,并指出有效位數(shù)。(編制程序時(shí)用單精度)通過本次上機(jī)題,你明白了什么?二、MATLAB程序N=input('請(qǐng)輸入N(N>1):');AccurateValue二single((0T/(N+1)T/N+3/2)/2);%single使其為單精度Sn1=single(O);%從小到大的順序fora=2:N;Sn仁Sn1+1/(a八2-1);endSn2=single(0);%從大到小的順序fora=2:N;Sn2=Sn2+1/((N-a+2廠2-1);endfprintf('Sn的值(N=%d)\n',N);disp('')fprintf('精確值%f\n',AccurateValue);fprintf('從大到小計(jì)算的結(jié)果%f\n',Sn1);fprintf('從小到大計(jì)算的結(jié)果%f\n',Sn2);disp('')三、結(jié)果請(qǐng)輸入N(N>1):100Sn的值(N=100)精確值0.740049從大到小計(jì)算的結(jié)果0.740049從小到大計(jì)算的結(jié)果0.740050請(qǐng)輸入N(N>1):10000Sn的值(N=10000)精確值0.749900從大到小計(jì)算的結(jié)果0.749852從小到大計(jì)算的結(jié)果0.749900請(qǐng)輸入N(N>1):1000000Sn的值(N=1000000)精確值0.749999從大到小計(jì)算的結(jié)果0.749852從小到大計(jì)算的結(jié)果0.749999四、結(jié)果分析可以得出,算法對(duì)誤差的傳播又一定的影響,在計(jì)算時(shí)選一種好的算法可以使結(jié)果更為精確。從以上的結(jié)果可以看到從大到小的順序?qū)е麓髷?shù)吃小數(shù)的現(xiàn)象容易產(chǎn)生較大的誤差,求和運(yùn)算從小數(shù)到大數(shù)算所得到的結(jié)果才比較準(zhǔn)確。第二章一、題目給定初值xo及容許誤差£,編制牛頓法解方程f(x)=0的通用程序。給定方程f(x)—x33—x=0,易知其有三個(gè)根X]=_乜3,X2=0,=y'3①由牛頓方法的局部收斂性可知存在6〉0,當(dāng)xoW(_§,+§)時(shí),Newton迭代序列收斂于根x2*。試確定盡可能大的6。②試取若干初始值,觀察當(dāng)x°g(一3,-1),(-1,-6),(-6,+6),(6,1),(1,+8)時(shí)Newton序列的收斂性以及收斂于哪一個(gè)根。(3)通過本上機(jī)題,你明白了什么?二、MATLAB程序文件fx.mfunctionFx二fx(x)%%定義函數(shù)f(x)Fx=xY/3-x;文件dfx.mfunctionFx=dfx(x)Fx二x八2-1;%%定義導(dǎo)函數(shù)df(x)%%Newton法求方程的根%%clearef=10八一6;%這里取容許誤差10八-6k=0;x0=input('請(qǐng)輸入Xo的值:’);disp('kXk');fprintf('0%f\n',x0);flag=1;whileflag==1&&k<=10八3%使用空格將其分隔開x1=x0-fx(x0)/dfx(x0);ifabs(x1-x0)<efflag=0;endk=k+1;x0=x1;fprintf('%d%f\n',k,x0);end%%尋找最大的delta值%%clear%%flag=1;k=1;x0=0;whileflag==1delta二k*10八-6;%delta與k有關(guān)x0=delta;k=k+1;m=0;flag1=1;whileflag1==1&&m<=10八3x1=x0-fx(x0)/dfx(x0);ifabs(x1-x0)<10八一6flag1=0;%給定容許誤差endm=m+1;x0=x1;endifflag1==l||abs(x0)>=10八-6%未小于給定誤差時(shí)停止循環(huán)flag=0;endendfprintf('delta的最大值是%f\n',delta);三、結(jié)果1.運(yùn)行search.m文件結(jié)果為:delta的最大值為0.774597即得最大的5為0.774597,Newton迭代序列收斂于根x*=0的最大區(qū)間為2(-0.774597,0.774597)。2.(1)區(qū)間(—8,-1)上取-1000,-100,-50,-30,-10,-8,-7,-5,-3

kXkkXkkXk0-10000.0000000-100.0000000-50.0000001-6666.6667331-66.6733341-33.3466722-4444.4445892-44.4588912-22.2511253-2962.9632093-29.6542633-14.8641054-1975.3090314-19.7920164-9.9544585-1316.8730255-13.2284475-6.7039606-877.9158566-8.8696516-4.5710137-585.2779977-5.9892317-3.2005208-390.1864708-4.1073248-2.3645159-260.1260229-2.9107559-1.91970310-173.41991110-2.20018910-1.75640511-115.61711811-1.84868711-1.73254812-77.08384512-1.74223512-1.73205113-51.39788013-1.73213914-34.27822914-1.73205115-22.87161815-1.73205116-15.27694917-10.22845918-6.88478019-4.68877220-3.27480721-2.40771422-1.93975023-1.76125924-1.73276225-1.732051

26-1.732051kXkkXkkXk0-30.0000000-10.0000000-8.0000001-20.0222471-6.7340071-5.4179892—13.3815442-4.5905702-3.7393793—8.9711293-3.2128403-2.6849344-6.0560004-2.3716534-2.0782465-4.1505035-1.9229815-1.8029286-2.9375246-1.7571756-1.7360237-2.2150467-1.7325807-1.7320648-1.8547148-1.7320518-1.7320519-1.7432369-1.7320519-1.73205110-1.73215811-1.73205112-1.732051kXkkXkkXk0-7.0000000-5.0000000-3.0000001-4.7638891-3.4722221-2.2500002-3.3223182-2.5241802-1.8692313-2.4355333-1.9960683-1.745810

4-1.9529154-1.7766184-1.7322125-1.7646305-1.7336745-1.7320516-1.7329316-1.7320536-1.7320517-1.7320517-1.7320518-1.7320518-1.732051結(jié)果顯示,以上初值迭代序列均收斂于-1.732051,即根x*。1(2)在區(qū)間(—1,-§)即區(qū)間(-1,-0.774597)上取-0.774598,-0.8,-0.85,-0.9,-0.99,計(jì)算結(jié)果如下:kXkkXkkXk0-0.7745980-0.80000000.85000010.77460510.9481481-1.4753752-0.7746452-5.6253702-1.81944430.7748843-3.8726253-1.737969

4-0.7763244-2.7661974-1.73208150.7850495-2.1213675-1.7320516-0.8406416-1.8182926-1.73205171.3501877-1.73782281.9938308-1.73207991.7759639-1.732051101.73362810-1.732051111.732053121.732051131.732051kXkkXk0-0.9000000-0.99000012.557895132.50582922.012915221.69108131.781662314.49152141.73404949.70723851.73205456.54090661.73205164.46496671.73205173.13384082.32607591.902303101.752478111.732403121.732051

131.732051計(jì)算結(jié)果顯示,迭代序列局部收斂于-1.732051,即根x*,局部收斂于11.730251,即根x*。3有上題可知,在區(qū)間(-0.774597,0.774597)上,在整個(gè)區(qū)間上均收斂于0,即根x*。2在區(qū)間(,1)即區(qū)間(0.774597,1)上取0.774598,0.8,0.85,0.9,0.99,計(jì)算結(jié)果如下:kXkkXkkXk00.77459800.80000000.8500001-0.7746051-0.9481481-1.47537520.77464525.6253702-1.8194443-0.77488433.8726253-1.73796940.77632442.7661974-1.7320815-0.78504952.1213675-1.73205160.84064161.8182926-1.7320517-1.35018771.7378228-1.99383081.7320799-1.77596391.732051

-1.733628-1.732053-1.732051-1.732051101.732051kXkkXk00.90000000.9900001-2.5578951-32.5058292-2.0129152-21.6910813-1.7816623-14.4915214-1.7340494-9.7072385-1.7320545-6.5409066-1.7320516-4.4649667-1.7320517-3.1338408-2.3260759-1.90230310-1.75247811-1.73240312-1.73205113-1.732051計(jì)算結(jié)果顯示,迭代序列局部收斂于-1.732051,即根x*,局部收斂于11.730251,即根x*。3

(5)區(qū)間(1,)上取100,60,20,10,7,6,4,3,1.5,計(jì)算結(jié)果如下:kXkkXkkXk0100.000000060.000000020.000000166.673334140.011114113.366750244.458891226.69074928.961323329.654263317.81884536.049547419.792016411.91676244.146328513.22844758.00084862.21360568.86965165.41854671.85412675.98923173.73973681.74313684.10732482.68515191.73215692.91075592.078360101.732051102.200189101.802967111.732051111.848687111.736027121.742235121.732064131.732139131.732051141.732051141.732051151.732051kXkkXkkXk010.00000007.00000006.00000016.73400714.76388914.11428624.59057023.32231822.91506833.21284032.43553332.20257842.37165341.95291541.849650

51.92298151.76463051.74239261.75717561.73293161.73214271.73258071.73205171.73205181.73205181.73205181.73205191.732051kXkkXkkXk04.00000003.00000001.50000012.84444412.25000011.80000022.16372421.86923121.73571431.83428131.74581031.73206241.74000741.73221241.73205151.73210551.73205151.73205161.73205161.73205171.732051結(jié)果顯示,以上初值迭代序列均收斂于1.732051,即根x*。3四、結(jié)果分析綜上所述:(,-1)區(qū)間收斂于-1.73205,(-1,-5)區(qū)間局部收斂于1.73205,局部收斂于-1.73205,(-5,5)區(qū)間收斂于0,(5,1)區(qū)間類似于(-1,-5)區(qū)間,(1,+8)收斂于1.73205。通過本上機(jī)題,明白了對(duì)于多根方程,Ne毗on法求方程根時(shí),迭代序列收斂于某一個(gè)根有一定的區(qū)間限制,在一個(gè)區(qū)間上,可能會(huì)局部收斂于不同的根。第三章一、題目列主元Gauss消去法對(duì)于某電路的分析,歸結(jié)為求解線性方程組RI=V?!?1—13000—10000、—1335—90—1100000—931—100000000—1079—30000—9其中R=000—3057—70—500000—747—300000000—3041000000—50027—2<000—9000—229丿Vt=(—15,27,—23,0,—20,12,—7,7,10)T編制解n階線性方程組Ax=b的列主元高斯消去法的通用程序;用所編程序線性方程組RI=V,并打印出解向量,保留5位有效數(shù);二、MATLAB程序%%列主元Gauss消去法求解線性方程組%%%%參數(shù)輸入n二input('請(qǐng)輸入矩陣A的階數(shù):n二');%輸入線性方程組階數(shù)nb=zeros(1,n);A=input('請(qǐng)輸入矩陣A:');%輸入行向量bb(1,:)=input('請(qǐng)輸入行向量%輸入行向量bb=b';%得到列向量bC=[A,b];%得到增廣矩陣%%列主元消去得上三角矩陣fori=1:n-1[maximum,index]二max(abs(C(i:n,i)));%將最大元素位置放在index行中index=index+i-1;T=C(index,:);%T作為一個(gè)中轉(zhuǎn)站,交換兩行C(index,:)=C(i,:);C(i,:)=T;fork=i+1:n%%列主元消去ifC(k,i)~=0C(k,:)=C(k,:)-C(k,i)/C(i,i)*C(i,:);endendend%%回代求解%%x=zeros(n,1);x(n)=C(n,n+1)/C(n,n);fori=n-1:-1:1x(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('上三角矩陣為:’)fork=1:nfprintf('%f',A(k,:));fprintf('\n');enddisp('方程的解為:’);fprintf('%.5g\n',x);%以5位有效數(shù)字輸出結(jié)果三、結(jié)果請(qǐng)輸入矩陣A的階數(shù):n=9請(qǐng)輸入矩陣A:[31-13000-10000;-1335-90-110000;0-931-1000000;00-1079-30000-9;000-3057-70-50;0000-747-3000;00000-304100;0000-50027-2;000-9000-29]請(qǐng)輸入行向量b:[-1527-230-2012-7710]三角矩陣為:31.000000-13.0000000.0000000.0000000.000000-10.0000000.0000000.00000031.000000-13.0000000.0000000.0000000.000000-10.0000000.0000000.0000000.201050.201050.0000000.00000029.548387-9.0000000.000000-11.000000-4.1935480.0000000.0000000.0000000.0000000.00000028.258734-10.000000-3.350437-1.2772930.0000000.0000000.0000000.0000000.0000000.00000075.461271-31.185629-0.4519990.0000000.000000-9.0000000.0000000.0000000.0000000.00000044.602000-7.1796950.000000-5.000000-3.5779940.0000000.0000000.0000000.000000-0.00000045.873193-30.000000-0.784718-0.5615430.0000000.0000000.0000000.000000-0.000000-0.00000021.380698-0.513187-0.3672360.0000000.0000000.0000000.000000-0.000000-0.0000000.00000026.413085-2.4199960.0000000.0000000.0000000.000000-0.000000-0.0000000.0000000.00000027.389504方程的解為-0.289230.34544-0.71281-0.22061-0.43040.15431-0.057823第四章:多項(xiàng)式插值與函數(shù)最佳逼近一、題目:(1)編制求第一型3次樣條插值函數(shù)的通用程序;2)已知汽車曲線型值點(diǎn)的數(shù)據(jù)如下:xi012345678910yi2.513.304.044.705.225.545.785.405.575.705.80端點(diǎn)條件為人=0.8,時(shí)0.2。用所編制程序求車門的3次樣條插值函數(shù)S(x),并打印出S(i+0.5),i=0,1,...9。二、MATLAB程序n二input('Inputn:n二’);%n=10n二n+1;x二zeros(1,n);%x用來存儲(chǔ)xy=zeros(1,n);%y用來存儲(chǔ)yx(1,:)=input('輸入x:');%分別輸入x,yy(1,:)=input('輸入y:');dy0=input('輸入y(0)的一階導(dǎo)數(shù):’);%輸入邊界條件dyn二input('輸入y(n)的一階導(dǎo)數(shù):’);d=zeros(n,1);h=zeros(1,nT);%h為兩個(gè)點(diǎn)之間的距離f1=zeros(1,nT);f2=zeros(1,n-2);fori=1:n-1h(i)=x(i+1)-x(i);f1(i)=(y(i+1)—y(i))/h(i);%—階差商endfori=2:n-1f2(i)=(f1(i)-f1(i-1))/(x(i+1)-x(i-1));%求二階差商d(i)=6*f2(i);endd(1)=6*(f1⑴-dy0)/h(1);%補(bǔ)充d1和dnd(n)=6*(dy-f1(nT))/h(nT);A=zeros(n);miu=zeros(1,n-2);lamda二zeros(1,n-2);fori=1:n-2miu(i)=h(i)/(h(i)+h(i+1));lamda(i)=1-miu(i);endA(1,2)=1;A(n,nT)=1;fori=1:nA(i,i)=2;endfori=2:n-1A(i,i—1)=miu(i—1);A(i,i+1)=lamda(i-1);endM=A\d;

symsx;fori=1:n-1Sx(i)二collect(y(i)+(f1(i)-(M(i)/3+M(i+1)/6)*h(i))*(x-x(i))+M(i)/2*(x-x(i)廠2+(M(i+1)-M(i))/(6*h(i))*(x-x(i)廠3);Sx(i)=vpa(Sx(i),4);endS=zeros(1,nT);fori=1:n-1x=x(i)+0.5;S(i)=y(i)+(f1(i)-(M(i)/3+M(i+1)/6)*h(i))*(x-x(i))+M(i)/2*(x-x(i))八2+、(M(i+1)-M(i))/(6*h(i))*(x-x(i)廠3;end%輸出結(jié)果disp('S(x)=');fori=1:n-1fprintf(%s(%d,%d)\n',char(Sx(i)),x(i),x(i+1))fprintf(%s(%d,%d)\n',char(Sx(i)),x(i),x(i+1))')disp('end')disp('S(i+0.5)')disp('x(i+0.5)S(i+0.5)')disp('x(i+0.5)S(i+0.5)')fori=1:n-1endfprintf(%d%0.4f%0.4f\n',x(i)+0.5,S(i))endfprintf(%d%0.4f%0.4f\n',x(i)+0.5,S(i))三、結(jié)果1.數(shù)據(jù)輸入輸入n:n=10輸入x:[012345678910]輸入y:[2.513.304.044.705.225.545.785.405.575.705.80]輸入y(0)的一階導(dǎo)數(shù):0.8輸入y(n)的一階導(dǎo)數(shù):0.22.計(jì)算結(jié)果x屬于區(qū)間[0,1]時(shí);S(x)=2.51+0.8(x)-0.0014861(x)(x)-0.00851395(x)(x)(x)x屬于區(qū)間[1,2]時(shí);S(x)=3.3+0.771486(x-1)-0.027028(x-1)(x-1)-0.00445799(x-1)(x-1)(x-1)x屬于區(qū)間[2,3]時(shí);S(x)=4.04+0.704056(x-2)-0.0404019(x-2)(x-2)-0.0036543(x-2)(x-2)(x-2)x屬于區(qū)間[3,4]時(shí);S(x)=4.7+0.612289(x-3)-0.0513648(x-3)(x-3)-0.0409245(x-3)(x-3)(x-3)x屬于區(qū)間[4,5]時(shí);S(x)=5.22+0.386786(x-4)-0.174138(x-4)(x-4)+0.107352(x-4)(x-4)(x-4)x屬于區(qū)間[5,6]時(shí);S(x)=5.54+0.360567(x-5)+0.147919(x-5)(x-5)-0.268485(x-5)(x-5)(x-5)x屬于區(qū)間[6,7]時(shí);S(x)=5.78-0.149051(x-6)-0.657537(x-6)(x-6)+0.426588(x-6)(x-6)(x-6)x屬于區(qū)間[7,8]時(shí);S(x)=5.4-0.184361(x-7)+0.622227(x-7)(x-7)-0.267865(x-7)(x-7)(x-7)x屬于區(qū)間[8,9]時(shí);S(x)=5.57+0.256496(x-8)-0.181369(x-8)(x-8)+0.0548728(x-8)(x-8)(x-8)x屬于區(qū)間[9,10]時(shí);S(x)=5.7+0.058376(x-9)-0.0167508(x-9)(x-9)+0.0583752(x-9)(x-9)(x-9)、?ix(i+0.5)S(i+0.5)10.52.90856421.53.67842932.54.38147143.54.98818854.55.38327765.55.72370276.55.59441487.55.42989398.55.659765109.55.732297四、體會(huì)通過這次對(duì)三次樣條插值函數(shù)的編程,對(duì)三次樣條插值的計(jì)算有了更加深刻的理解。對(duì)復(fù)雜公式編程實(shí)現(xiàn)能力有了一定的提高。第五章數(shù)值積分與數(shù)值微分一、題目:⑴給定積分I(f)=Jd(jbf(x,y)dx)dy。取初始步長(zhǎng)h和k,及精度S。應(yīng)用ca復(fù)化梯形公式,采用逐次二分步長(zhǎng)的方法,并應(yīng)用外推思想編制計(jì)算if)通用程序。計(jì)算至相鄰兩次近似值之差的絕對(duì)值不超過S為止。(2)用所編程序計(jì)算積分I(f)=A6(J"3tg(x2+y2)dx)dy,取£=丄x10-5o002二、MATLAB程序function[BEST,R]二GET(f,a,b,c,d,m,n,epsilon)R=[];COUNT=1;R(C0UNT,1)=getT(f,a,b,c,d,2V0UNT*m,2S0UNT*n);C0UNT=2;R(C0UNT,1)=getT(f,a,b,c,d,2V0UNT*m,2S0UNT*n);R(C0UNT-1,2)=4/3*R(C0UNT,1)-1/3*R(C0UNT-1,1);R1=R(1,1);R2=R(2,1);co=[4/3-1/3;16/15T/15;64/63-1/63];whileabs(R1

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(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ǔ)空間,僅對(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)論