?? newton
字號(hào):
Newton插值2007-07-16 18:37#include<iostream>
using namespace std;
#include<math.h>
#define N 5 //以五點(diǎn)為例
void main()
{
int i,j;
float f[N+1][N+1];
float x[N],y[N];
float t;
cout<<"Please input the array of x:\n";
for(i=0;i<N;i++) cin>>x[i];
printf("Please input the array of y:\n");
for(j=0;j<N;j++) cin>>y[j];
for(i=1;i<N;i++)
for(j=i;j<N;j++)
f[i][j]=0;
for(j=0;j<N;j++)
f[0][j]=y[j];
for(i=1;i<N;i++)
for(j=i;j<N;j++)
f[i][j]=(f[i-1][j]-f[i-1][j-1])/(x[j]-x[j-i]);
cout<<"Please input t \nt=";
cin>>t;
float m=0,n=1;
for(i=0;i<N;i++)
{
m=m+n*f[i][i];
n=n*(t-x[i]);
}
cout<<"Using Newton Interpolation method,the result is:\n";
cout<<"ln("<<t<<")="<<m<<"\n";
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -