數(shù)值分析教學(xué)shiya_第1頁
數(shù)值分析教學(xué)shiya_第2頁
數(shù)值分析教學(xué)shiya_第3頁
數(shù)值分析教學(xué)shiya_第4頁
數(shù)值分析教學(xué)shiya_第5頁
已閱讀5頁,還剩17頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

數(shù)值試驗題2

2.1編制分段線性插值和分段三次Hermite插值程序,對被插函數(shù)插值區(qū)間,分成10等分,求分段線性插值函數(shù)在各節(jié)點間中點處的值,并畫出分段線性插值函數(shù)和的圖形。2.2給定數(shù)據(jù)如下表:編制程序求三次樣條插值函數(shù)在插值中點的樣條函數(shù)值,并作點集和樣條插值函數(shù)的圖形,滿足的邊界條件為2.3對下列數(shù)據(jù)作三次多項式擬合,取權(quán)數(shù),給出擬合多項式的系數(shù)、平方誤差并作離散數(shù)據(jù)和擬合多項式的圖形。下面6張是第1題>>x=[-5,-4,-3,-2,-1,0,1,2,3,4,5];y=1./(1+x.^2)y=0.03850.05880.10000.20000.50001.00000.50000.20000.10000.05880.0385首先算出f(x)的值如下:分段線性插值functionI=f(x)a=[-5,-4,-3,-2,-1,0,1,2,3,4,5];b=[0.0385,0.0588,0.1000,0.2000,0.5000,1.0000,0.5000,0.2000,0.1000,0.0588,0.0385];n=length(x);fori=1:n-1I(i)=b(i)*(x(i)-a(i+1))/(a(i)-a(i+1))+b(i+1)*(x(i)-a(i))/(a(i+1)-a(i));end>>x=[-4.5,-3.5,-2.5,-1.5,-0.5,0.5,1.5,2.5,3.5,4.5];I=f(x)I=0.04860.07940.15000.35000.75000.75000.35000.15000.07940.0486運行結(jié)果如下:functionI=f(x)a=[-5,-4,-3,-2,-1,0,1,2,3,4,5];m=[0.0148,0.0277,0.0600,0.1600,0.5000,0,-0.5000,-0.1600,-0.0600,-0.0277,-0.0148]b=[0.0385,0.0588,0.1000,0.2000,0.5000,1.0000,0.5000,0.2000,0.1000,0.0588,0.0385];n=length(x);fori=1:n-1l(i)=(1+2*(x(i)-a(i+1))/(a(i)-a(i+1))*((x(i)-a(i))/(a(i+1)-a(i))).^2;n(i)=(x(i)-a(i+1))*((x(i)-a(i))/(a(i+1)-a(i))).^2;

I(i)=b(i)*a(i)+m(i)*n(i)endHermite插值x=[-4.5,-3.5,-2.5,-1.5,-0.5,0.5,1.5,2.5,3.5,4.5];f(x)ans=Columns1through70.04860.07940.15000.35000.75000.75000.3500Columns8through100.15000.07940.0486得f(x)圖形如下:輸入:>>fplot('1./(1+x.^2)',[-5,5])x=[-5,-4,-3,-2,-1,0,1,2,3,4,5];y=[0.0385,0.0588,0.1000,0.2000,0.5000,1.0000,0.5000,0.2000,0.1000,0.0588,0.0385];plot(x,y)>>畫圖命令如下:圖形如下:下面6張是第2題functionSanciyangtiao(X,Y,a,b)%a=f'(1),b=f'(n)n=length(X);fori=1:n-1h(i)=X(i+1)-X(i);endforj=2:n-1u(j)=h(j-1)/(h(j-1)+h(j));t(j)=1-u(j);d(j)=6*((Y(j+1)-Y(j))/h(j)-(Y(j)-Y(j-1))/h(j-1))/(h(j-1)+h(j));endt(1)=1;u(n)=1;d(1)=6/h(1)*((Y(2)-Y(1))/h(1)-a);d(n)=6/h(n-1)*(b-(Y(n)-Y(n-1))/h(n-1));fori=1:nA(i,i)=2;A(1,2)=1;A(n,n-1)=1;forj=2:n-1A(j,j-1)=u(j);A(j,j+1)=t(j);ifabs(i-j)>1A(i,j)=0;endendend程序(1)(a)D=d';N=A\D;M=N';fori=1:n-1H(i)=(M(i+1)-M(i))/(6*h(i));I(i)=(M(i)*X(i+1)-M(i+1)*X(i))/(2*h(i));J(i)=(M(i+1)*X(i)^2-M(i)*X(i+1)^2+2*(Y(i+1)-Y(i))+h(i)^2/3*(M(i)-M(i+1)))/(2*h(i));K(i)=(M(i)*X(i+1)^3-M(i+1)*X(i)^3+(6*Y(i)-M(i)*h(i)^2)*X(i+1)-(6*Y(i+1)-M(i+1)*h(i)^2)*X(i))/(6*h(i));endfori=1:n-1Q(i)=M(i)*(X(i+1)-(X(i)+X(i+1))/2)^3/(6*h(i))+(M(i+1)*((X(i)+X(i+1))/2-X(i))^3)/(6*h(i))+(Y(i)-M(i)*(h(i))^2/6)*(X(i+1)-(X(i)+X(i+1))/2)/h(i)+(Y(i+1)-M(i+1)*(h(i))^2/6)*((X(i)+X(i+1))/2-X(i))/h(i);enddisp(Q)fori=1:n-1x=X(i):0.001:X(i+1);z=H(i)*x.^3+I(i)*x.^2+J(i)*x+K(i);plot(x,z,X,Y,'*');holdonend>>X=[012345678910];>>Y=[0.00.791.532.192.713.033.272.893.063.193.29];>>sanciyangtiao8(X,Y,0.8,0.2)0.39861.16841.87152.47822.87333.21373.08442.91993.14983.2223functionSanciyangtiao(X,Y)n=length(X);fori=1:n-1h(i)=X(i+1)-X(i);endforj=2:n-1u(j)=h(j-1)/(h(j-1)+h(j));t(j)=1-u(j);d(j)=6*((Y(j+1)-Y(j))/h(j)-(Y(j)-Y(j-1))/h(j-1))/(h(j-1)+h(j));endt(1)=0;u(n)=0;d(1)=0;d(n)=0;fori=1:nA(i,i)=2;A(1,2)=0;A(n,n-1)=0;forj=2:n-1A(j,j-1)=u(j);A(j,j+1)=t(j);ifabs(i-j)>1A(i,j)=0;endendendD=d';N=A\D;M=N';fori=1:n-1H(i)=(M(i+1)-M(i))/(6*h(i));I(i)=(M(i)*X(i+1)-M(i+1)*X(i))/(2*h(i));J(i)=(M(i+1)*X(i)^2-M(i)*X(i+1)^2+2*(Y(i+1)-Y(i))+h(i)^2/3*(M(i)-M(i+1)))/(2*h(i));K(i)=(M(i)*X(i+1)^3-M(i+1)*X(i)^3+(6*Y(i)-M(i)*h(i)^2)*X(i+1)-(6*Y(i+1)-M(i+1)*h(i)^2)*X(i))/(6*h(i));endfori=1:n-1Q(i)=M(i)*(X(i+1)-(X(i)+X(i+1))/2)^3/(6*h(i))+(M(i+1)*((X(i)+X(i+1))/2-X(i))^3)/(6*h(i))+(Y(i)-M(i)*(h(i))^2/6)*(X(i+1)-(X(i)+X(i+1))/2)/h(i)+(Y(i+1)-M(i+1)*(h(i))^2/6)*((X(i)+X(i+1))/2-X(i))/h(i);enddisp(Q)fori=1:n-1x=X(i):0.001:X(i+1);z=H(i)*x.^3+I(i)*x.^2+J(i)*x+K(i);plot(x,z,X,Y,'*');holdonend>>X=[012345678910];>>Y=[0.00.791.532.192.713.033.272.893.063.193.29];>>sanciyangtiao2(X,Y)0.39841.16851.87152.47822.87333.21383.08412.92093.14593.2368下面5張是第三題

對數(shù)據(jù)作三次多項式的擬合得到多項式為:擬合多項式的平方誤差為:err=0.2500多項式擬合的程序如下:functionz=f(x,y)%二次表達(dá)式,按行或按列向量輸入x和y.n=length(x);sx=sum(x);sx2=sum(x.^2);sx3=sum(x.^3);sx4=sum(x.^4);sx5=sum(x.^5);sx6=sum(x.^6);sy=sum(y);sxy=sum(x.*y);sx2y=sum(x.*x.*y);sx3y=sum(x.*x.*x.*y);A=[nsxsx2sx3,sxsx2sx3sx4,sx2sx3sx4sx5,sx3sx4sx5sx6];

r=[sysxysx2ysx3y]';t=A\r;a=t(1),b=t(2),c=t(3),d=t(4)table=[xy(a+b*x+c*x.^2+d*x.^3)(y-(a+b*x+c*x.^2+d*x.^3))]disp('xy(a+b*x+c*x.^2+d*x.^3)(y-(a+b*x+c*x.^2+d*x.^3))')err=sum(table(4).^2)輸入:x=[-1.0,-0.5,0.0,0.5,1.0,1.5,2.0];y=[-4.447,-0.452,0.551,0.048,-0.447,0.549,4.552];f(x,y)得多項式系數(shù)和平方誤差為:a=0.5491b=-3.9683e-005c=-2.9977d=1.9991err=0.2500輸入下面命令得擬合圖形:>>fpl

溫馨提示

  • 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

提交評論