先使用牛頓向前的內插多項式
============================
x f(x) 第一項P'n(x) 前二項P'n(x) 前三項P'n(x)
0.5 0.4794
0.6 0.5646
0.8 0.7174
1.05 0.8674
============================
/* ex3-3.c is for developing the divided-defference
* table for Newton Interpolation polynomial.
*/
#include <stdio.h>
void main()
{
int i,j,n=3;
double x[]= {0.5 , 0.6 , 0.8 , 1.05};
double f[40][40];
f[0][0] = 0.4794;
f[1][0] = 0.5646;
f[2][0] = 0.7174;
f[3][0] = 0.8674;
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;
}
輸出畫面
Divided Difference Table:
=========================
i x(i) f(i) f(i,i+1) f(i,i+1.i+2), ......
0 0.50000 0.47940 0.85200 -0.29333 -0.12929
1 0.60000 0.56460 0.76400 -0.36444
2 0.80000 0.71740 0.60000
3 1.05000 0.86740
...Program finished with exit code 4
P'n(x)= 0.852 + -0.2933 * [(x-0.6) + (x- 0.5) ] + -0.1293 *[ (x-0.8) + (x-0.6) + (x- 0.5)
x=0.5
第一項P'n(x)
P'n(0.5)=0.852
前二項P'n(x)
P'n(0.5)=0.852 + -0.2933 * [ (0.5-0.6) + (0.5-0.5) = 0.8813
前三項P'n(x)
P'n(0.5)= 0.852 + -0.2933 * [(0.5-0.6) + (0.5- 0.5) ] + -0.1293 *[ (0.5-0.8) + ( 0.5 - 0.6) + ( 0.5 - 0.5) = 0.87745
x=0.6
.第一項P'n(x)
P'n(0.6)=0.852
前二項P'n(x)
P'n(0.6)=0.852 + -0.2933 * [ (0.6-0.6) + (0.6-0.5) = 0.82267
前三項P'n(x)
P'n(0.6)= 0.852 + -0.2933 * [(0.6-0.6) + (0.6 - 0.5) ] + -0.1293 *[ (0.6-0.8) + ( 0.6 - 0.6) + ( 0.6 - 0.5) = 0.82526
x=0.8
.第一項P'n(x)
P'n(0.8)=0.852
前二項P'n(x)
P'n(0.8)=0.852 + -0.2933 * [ (0.8-0.6) + (0.8-0.5) = 0.70534
前三項P'n(x)
P'n(0.8)= 0.852 + -0.2933 * [(0.8-0.6) + (0.8 - 0.5) ] + -0.1293 *[ (0.8-0.8) + ( 0.8 - 0.6) + ( 0.8 - 0.5) = 0.69758
................................................................
................................................................
沒有留言:
張貼留言