ex1-9.c is for developing the divided-defference table for Newton Interpolation polynomial.
輸入TEXT
n=5
0.0 -6.0
0.1 -5.89483
0.3 -5.65014
0.6 -5.17788
1.0 -4.28172
1.1 -3.99583
輸出畫面
程式畫面 設定C語言
程式
/* ex1-9.c is for developing the divided-defference
* table for Newton Interpolation polynomial.
*/
#include <stdio.h>
void main()
{
int i,j,n;
double f[40][40],x[40];
scanf("n=%d",&n);
for(i=0;i<=n;i++)
{
scanf("%lf %lf ",&x[i],&f[i][0]);
}
printf("\n Divided Difference Table:\n");
printf(" =========================\n");
for(j=1;j<=n;j++)
{
for(i=0;i<=n-j;i++)
{
f[i][j]=(f[i+1][j-1]-f[i][j-1])/(x[i+j]-x[i]);
}
}
printf("i x(i) f(i) f(i,i+1) f(i,i+1.i+2), ......\n");
for(i=0;i<=n;i++)
{
printf("%d %8.5lf ",i,x[i]);
for(j=0;j<=n-i;j++)
{
printf("%8.5lf ",f[i][j]);
}
printf("\n");
}
return;
}



沒有留言:
張貼留言