資源描述:
《拉格朗日插值與牛頓插值》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、一、目的1.通過本實(shí)驗(yàn)加深對(duì)拉格朗日插值和牛頓插值法構(gòu)造過程的理解;2.能對(duì)上述兩種插值法提出正確的算法描述編程實(shí)現(xiàn)。二、內(nèi)容與設(shè)計(jì)思想自選插值問題,編制一個(gè)程序,分別用拉格朗日插值法和牛頓插值法求解某點(diǎn)的函數(shù)近似值。(從課件jsff04.ppt或教材習(xí)題中選題)已知y=f(x)的數(shù)據(jù)表如下,求t=0.63處的函數(shù)值z(mì)=f(t)。ixiyiixiyi10.100.90483760.570.56552520.150.86070870.700.49658530.250.77880180.850.4274154
2、0.400.67032090.930.39455450.500.606531101.000.367879三、使用環(huán)境操作系統(tǒng):windonsXP軟件環(huán)境:VC6.0四、核心代碼及調(diào)試過程拉格朗日插值法:#include#include#include#defineN20doublelagrange(doublex[N],doubley[N],doublet,intn){doubles,ft;inti,j,k,m;ft=0.0;if(n<1)exit(
3、0);if(n==1){ft=y[0];exit(0);}if(n==2){第4頁共4頁ft=(t-x[1])*y[0]/(x[0]-x[1])+(t-x[0])*y[1]/(x[1]-x[0]);exit(0);}i=0;while((x[i]n-1)m=n-1;for(i=k;i<=m;i++){s=1.0;for(j=k;j<=m;j++)if(j!=i)s=s*(t-x[j])/(x[i]-x[j]);ft=ft
4、+s*y[i];}return(ft);}voidmain(){doublex[N]={0.10,0.15,0.25,0.40,0.50,0.57,0.70,0.85,0.93,1.00};doubley[N]={0.904837,0.860708,0.77801,0.670320,0.6065310,0.565525,0.496585,0.427418,0.394554,0.367879};doublet=0.63,ft;ft=lagrange(x,y,t,10);printf("f(0.63)=%lf
5、",ft);}運(yùn)行結(jié)果:第4頁共4頁牛頓插值法:#includevoidmain(){doublex[]={0.10,0.15,0.25,0.40,0.50,0.57,0.70,0.85,0.93,1.00};doubley[]={0.904837,0.860708,0.77801,0.670320,0.6065310,0.565525,0.496585,0.427418,0.394554,0.367879};doublec[10][10];doubleb[10];doublet=0
6、.63,ft;intn,i,j,k;for(i=0;i<10;i++)c[i][0]=y[i];for(i=1;i<10;i++)for(j=1;j<=i;j++)c[i][j]=(c[i][j-1]-c[i-1][j-1])/(x[i]-x[i-j]);b[9]=c[9][9];for(k=9;k>=1;k--)b[k-1]=c[k-1][k-1]+b[k]*(t-x[k-1]);ft=b[0];printf("f(t=0.63)=%lf",ft);}運(yùn)行結(jié)果:總結(jié)第4頁共4頁1.通過本實(shí)驗(yàn)加深了對(duì)
7、拉格朗日插值和牛頓插值法構(gòu)造過程的理解。2.通過編程能對(duì)上述兩種插值法提出正確的算法。六、附錄第4頁共4頁