最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

計算方法實驗三

2023-03-27 20:40 作者:啊啊啊不不不b  | 我要投稿



一、實驗名稱:

實驗三、插值逼近

二、實驗目的:

1. 掌握Lagrange插值、Newton插值的概念;

2. 編寫程序?qū)崿F(xiàn);

3. 觀察Runge現(xiàn)象。

三、實驗內(nèi)容及要求:


1.%E5%B7%B2%E7%9F%A5%E5%87%BD%E6%95%B0f(x)%3D1%2F(1%2Bx%5E2%20)%2Cx%E2%88%88%5B-5%2C5%5D%EF%BC%8C%E5%AF%B9%E5%AE%9A%E4%B9%89%E5%9F%9F%5B-5%2C5%5D%E8%BF%9B%E8%A1%8Cn%E7%AD%89%E5%88%86%EF%BC%9B

(a)取n%3D5%2C10%2C20%2C40,以等分節(jié)點為插值節(jié)點,構(gòu)造Lagrange插值公式,用程序計算各等分區(qū)間中點處的值,列表顯示(給出插值多項式及函數(shù)在等分區(qū)間中點處值),并分別作出和插值函數(shù)的圖形(將5個圖形畫在同一張圖里,并用不同顏色表示,四個插值多項式及一f(x)個圖形);

(b)取,以等分節(jié)點為插值節(jié)點,構(gòu)造牛頓插值函數(shù),用程序計算各等分區(qū)間中點處的值,列表顯示(給出插值多項式及函數(shù)在等分區(qū)間中點處值),并分別作出和插值函數(shù)的圖形(將5個圖形畫在同一張圖里,并用不同顏色表示,四個插值多項式及一個圖形);

(c)取,在剖分的基礎上簡歷分片線性Lagrange插值函數(shù),用程序計算各等分區(qū)間中點處的值,列表顯示(給出插值多項式及函數(shù)在等分區(qū)間中點處值),并分別作出和插值函數(shù)的圖形(將5個圖形畫在同一張圖里,并用不同顏色表示,四個插值多項式及一個圖形);

2.實現(xiàn)課本39頁例2.12,取,分別作出和插值函數(shù)的圖形(將5個圖形畫在同一張圖里,并用不同顏色表示,四個插值多項式及一個圖形);觀察Runge現(xiàn)象。

三、實驗步驟(或記錄)

1、(a)

插值多項式及函數(shù)在等分區(qū)間中點處值????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ????????????????????????

Y???? 0.038461538?? 0.042440318?? 0.047058824?? 0.052459016?? 0.058823529?? 0.066390041?? 0.075471698??????? 0.086486486?? 0.1?? 0.116788321?? 0.137931034?? 0.164948454?? 0.2?? 0.246153846?? 0.307692308??????? 0.390243902?? 0.5?? 0.64 0.8?? 0.941176471?? 1????? 0.941176471?? 0.8?? 0.64 0.5?? 0.390243902?? 0.307692308??????? 0.246153846?? 0.2?? 0.164948454?? 0.137931034?? 0.116788321?? 0.1?? 0.086486486?? 0.075471698??????? 0.066390041?? 0.058823529?? 0.052459016?? 0.047058824?? 0.042440318?? 0.038461538

y1??? -0.048076923 0.321153846?? 0.567307692?? 0.321153846?? -0.048076923??????????????????????????????????????????????????????????? ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ?????????????????????????????????????????

y2??? 1.57872099???? -0.226196289 0.253755457?? 0.235346591?? 0.84340743???? 0.84340743???? 0.235346591??????? 0.253755457?? -0.226196289 1.57872099????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

y3??? -39.95244903 3.4549578?????? -0.447051961 0.202422616?? 0.080659993?? 0.17976263???? 0.238445934??????? 0.395093054?? 0.636755336?? 0.94249038???? 0.94249038???? 0.636755336?? 0.395093054?? 0.238445934??????? 0.17976263???? 0.080659993?? 0.202422616?? -0.447051961 3.4549578?????? -39.95244903?????????????????????????????????? ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

y4??? -57409.17974 2287.728499?? -156.169717?? 15.42434982?? -1.939791158 0.39938813???? 0.014910807??????? 0.10858616???? 0.103537161?? 0.128151723?? 0.150063036?? 0.181523667?? 0.221349033?? 0.274733128??????? 0.345913865?? 0.441399666?? 0.566357999?? 0.719110364?? 0.876706771?? 0.984617272?? 0.984617272??????? 0.876706771?? 0.719110364?? 0.566357999?? 0.441399666?? 0.345913865?? 0.274733128?? 0.221349033??????? 0.181523667?? 0.150063036?? 0.128151723?? 0.103537161?? 0.10858616???? 0.014910807?? 0.39938813???? -1.939791158?? 15.42434982?? -156.169717?? 2287.728499?? -57409.17974

%構(gòu)造lagrange插值函數(shù),參考:https://blog.csdn.net/qq_44692057/article/details/108314856
? function y=lagr(X,Y,x)
? n=length(X);
? m=length(x);
? for i=1:m
? ??? z=x(i);
? ??? s=0;
? ??? for k=1:n
? ??????? p=1;
? ???? ???for j=1:n
? ??????????? if j~=k
? ??????????????? p=p*(z-X(j))/(X(k)-X(j));
? ??????????? end
? ??????? end
? ??????? s=p*Y(k)+s;
? ??? end
? ??? y(i)=s;
? end
?
? %輸入已知量(第2次a問)
? clear;
? n=[5 10 20 40];
? for a=1:4
? b=10/n(a);
? i=1:n(a)+1;
? j=-5:b:5;
? x=[i;j];
? for k=1:n(a)+1
? ??? ????X(k)=x(2,k)
? ??????? Y(k)=1/(1+X(k)*X(k));
? ??? end
? for l=1:n(a)
? ??? x0(l)=(x(2,l)+x(2,l+1))/2;
? end
? if a==1
? ??? y1=lagr(X,Y,x0);
? ??? x1=x0;
? elseif a==2
? ?????? ?????y2=lagr(X,Y,x0);
? ?????? ?????x2=x0;
? elseif a==3
? ?? ?????y3=lagr(X,Y,x0);
? ?? ?????x3=x0;
? elseif a==4
? ?? ?????y4=lagr(X,Y,x0);
? ?? ?????x4=x0;
?
? end
?
? end
? %畫圖比較精確值
? figure(1)
? xc=[-5:0.05:5]
? plot(xc,1./(1+xc.*xc),'k')
? hold on
? plot(x1,y1,'r')
? hold on
? plot(x2,y2,'y')
? hold on
? plot(x3,y3,'b')
? hold on
? plot(x4,y4,'g')
? hold off
? figure(2)
? xc=[-5:0.05:5]
? plot(xc,1./(1+xc.*xc),'k')
? hold on
? plot(x1,y1,'r')
? hold on
? plot(x2,y2,'y')
? hold on
? plot(x3,y3,'b')
? hold on
? plot(x4,y4,'g')
? hold off
? axis([-5,5,-1,1])
? 得出圖像

(b)

%構(gòu)造newton插值參考https://zhuanlan.zhihu.com/p/34883522
? function? ? N? = Newton( x,y,t )
? syms?? p ? ;?? %定義符號變量
? N = y(1);
? dd = 0;
? dxs = 1;
? n = length(x);
? for(i = 1:n-1)
? ??? ? for(j = i+1:n)
? ?? ?????dd(j) = (y(j)-y(i))/(x(j)-x(i));
? ??? end
? ??? temp1(i) = dd(i+1);
? ??? dxs = dxs*(p-x(i));
? ??? N = N + temp1(i)*dxs;
? ??? y = dd;
? end
? ? simplify(N);
? %以上為計算部分,下面是輸出規(guī)則;
? if(nargin == 2)
? ??? N = subs(N,'p','x');
? ??? N = collect(N);
? ??? N = vpa(N,4);
? else
? ??? m = length(t);
? ??? for i = ? 1:m
? ? ?????temp(i) = subs(N,'p',t(i));
? ??? end
? ??? N = temp;
? end
?
? %輸入已知量(第2次a問)
? clear;
? n=[5 10 20 40];
? for a=1:4
? b=10/n(a);
? i=1:n(a)+1;
? j=-5:b:5;
? x=[i;j];
? for k=1:n(a)+1
? ??????? X(k)=x(2,k)
? ??????? Y(k)=1/(1+X(k)*X(k));
? ??? end
? for l=1:n(a)
? ??? x0(l)=(x(2,l)+x(2,l+1))/2;
? end
? if a==1
? ??? y1=Newton(X,Y,x0);
? ??? x1=x0;
? elseif a==2
? ?????? ?????y2=Newton(X,Y,x0);
? ?????? ?????x2=x0;
? elseif a==3
? ?? ?????y3=Newton(X,Y,x0);
? ?? ?????x3=x0;
? elseif a==4
? ?? ?????y4=Newton(X,Y,x0);
? ?? ?????x4=x0;
?
? end
?
? end
? %畫圖比較精確值
? figure(1)
? xc=[-5:0.05:5]
? plot(xc,1./(1+xc.*xc),'k')
? hold on
? plot(x1,y1,'r')
? hold on
? plot(x2,y2,'y')
? hold on
? plot(x3,y3,'b')
? hold on
? plot(x4,y4,'g')
? hold off
? figure(2)
? xc=[-5:0.05:5]
? plot(xc,1./(1+xc.*xc),'k')
? hold on
? plot(x1,y1,'r')
? hold on
? plot(x2,y2,'y')
? hold on
? plot(x3,y3,'b')
? hold on
? plot(x4,y4,'g')
? hold off
? axis([-5,5,-1,1])
? 得出圖像

(c)

%構(gòu)造分段線性插值函數(shù)
? function y=fenduan(X,Y,x)
? n=length(X);
? m=length(x);
? for j=1:m
? ??? for i=1:n-1
? ?? ?????if x(j)>X(i)&&x(j)<=X(i+1)
? ??? ????????y(j)=((x(j)-X(i+1))/(X(i)-X(i+1)))*Y(i)+(((x(j)-X(i))/(X(i+1)-X(i)))*Y(i+1));
? ?? ?????end
? ??? end
? end
?
? %第二次c問
? clear;
? n=[5 10 20 40];
? for a=1:4
? b=10/n(a);
? i=1:n(a)+1;
? j=-5:b:5;
? x=[i;j];
? for k=1:n(a)+1
? ??????? X(k)=x(2,k)
? ??????? Y(k)=1/(1+X(k)*X(k));
? ??? end
? for l=1:n(a)
? ??? x0(l)=(x(2,l)+x(2,l+1))/2;
? end
? if a==1
? ??? y1=fenduan(X,Y,x0);
? ??? x1=x0;
? elseif a==2
? ?????? ?????y2=fenduan(X,Y,x0);
? ?????? ?????x2=x0;
? elseif a==3
? ?? ?????y3=fenduan(X,Y,x0);
? ?? ?????x3=x0;
? elseif a==4
? ?? ?????y4=fenduan(X,Y,x0);
? ?? ?????x4=x0;
?
? end
?
? end
? %畫圖比較精確值
? xc=[-5:0.05:5]
? plot(xc,1./(1+xc.*xc),'k')
? hold on
? plot(x1,y1,'r')
? hold on
? plot(x2,y2,'y')
? hold on
? plot(x3,y3,'b')
? hold on
? plot(x4,y4,'g')
? hold off

得出圖像

2、

%d2
? clear;
? n=[4 6 8 10];
? x0=[-1:0.005:1];
? for a=1:4
? b=2/n(a);
? X=-1:b:1;
? for i=1:n(a)+1
? Y(i)=1/(1+25*X(i)*X(i))
? end
? if a==1
? ??? y1=lagr(X,Y,x0);
? elseif a==2
? ??????????? y2=lagr(X,Y,x0);
? elseif a==3
? ??????? y3=lagr(X,Y,x0);
? elseif a==4
? ??????? y4=lagr(X,Y,x0);
? end
? end
? %畫圖比較精確值
? plot(x0,1./(1+25*x0.*x0),'k')
? hold on
? plot(x0,y1,'r')
? hold on
? plot(x0,y2,'y')
? hold on
? plot(x0,y3,'b')
? hold on
? plot(x0,y4,'g')
? hold off

得出圖像


計算方法實驗三的評論 (共 條)

分享到微博請遵守國家法律
定安县| 江永县| 海宁市| 庄河市| 泸溪县| 巴塘县| 涟源市| 遂宁市| 南昌县| 保康县| 白朗县| 东阿县| 宜阳县| 许昌市| 尉氏县| 修武县| 海阳市| 龙泉市| 锡林郭勒盟| 德昌县| 友谊县| 馆陶县| 金昌市| 龙游县| 巴彦淖尔市| 庄浪县| 芜湖市| 黄骅市| 巫溪县| 五原县| 紫阳县| 漳浦县| 图木舒克市| 农安县| 永靖县| 阿荣旗| 西宁市| 错那县| 屯门区| 廊坊市| 枝江市|