Docsity

newtons forward interpolation, Assignments of Mathematics

Toggle sidebar
bg1
Q) Implement to obtain the value of f'(1), f"(1), by using Newton's forward interpolation
formula for equally space data from the date given below:
(x, f(x))= (1, 0), (2, 0.693), (3, 1.099), (4, 1.386), (5, 1.609), (6, 1.792) (7, 1.946).
-->
ALGORITHM:
1) Enter the degree of polynomial 'n'
2) Enter the data sets 'xi' and 'fi'
3) Calculate the divided difference table as follows:
for i = 1 to n
for j=0 to n-i
fi[ i ][ j ] = fi[ i - 1 ][ j + 1 ]-fi[ i - 1 ][ j ]
End for j
End for i
4) Print the divided difference table as follows:
For j=0 to n
For I = 1 to n-j
Print fi[ i ][ j ]
End for i
Print new line
End for j
5) Enter value of x
6) Calculate h = xi[1] - xi[0]
7) Calculate k = x โ€“ xi[0]/h
8) f1 = fi[1][0]
f2 = fi[2][0]
f3 = fi[3][0]
f4 = fi[4][0]
f5 = fi[5][0]
f6 = fi[6][0]
9) Calculate First differentiation:
fx_1 = (1/h) * (f1 + ((2*k-1)/2)*f2 + ((3*k*k - 6*k + 2)/6)*f3 + ((4*k*k*k - 18*k*k + 22*k - 6)/24)*f4 +
((5*k*k*k*k - 40*k*k*k + 105*k*k - 100*k + 24)/120)*f5 + ((6*k*k*k*k*k - 75*k*k*k*k + 340*k*k*k -
675*k*k + 548*k - 120)/720)*f6 )
10) Calculate Second differentiation:
fx_2 = (1/(h*h)) * (f2 + (k-1)*f3 + ((6*k*k - 18*k + 11)/12)*f4 + ((2*k*k*k - 12*k*k + 21*k - 10)/12)*f5 +
((k*k*k*k - 10*k*k*k + 34*k*k - 45*k + 18.27)/24)*f6)
11) Print fx_1 and fx_2 as first and second differentiations respectively.
12) Stop
pf3
pf4

Partial preview of the text

Download newtons forward interpolation and more Assignments Mathematics in PDF only on Docsity!

Q) Implement to obtain the value of f'(1), f"(1), by using Newton's forward interpolation

formula for equally space data from the date given below:

(x, f(x))= (1, 0), (2, 0.693), (3, 1.099), (4, 1.386), (5, 1.609), (6, 1.792) (7, 1.946).

ALGORITHM:

  1. Enter the degree of polynomial 'n'
  2. Enter the data sets 'xi' and 'fi'
  3. Calculate the divided difference table as follows: for i = 1 to n for j=0 to n-i fi[ i ][ j ] = fi[ i - 1 ][ j + 1 ]-fi[ i - 1 ][ j ] End for j End for i
  4. Print the divided difference table as follows: For j=0 to n For I = 1 to n-j Print fi[ i ][ j ] End for i Print new line End for j
  5. Enter value of x
  6. Calculate h = xi[1] - xi[0]
  7. Calculate k = x โ€“ xi[0]/h
  8. f1 = fi[1][0] f2 = fi[2][0] f3 = fi[3][0] f4 = fi[4][0] f5 = fi[5][0] f6 = fi[6][0]
  9. Calculate First differentiation: fx_1 = (1/h) * (f1 + ((2k-1)/2)f2 + ((3kk - 6k + 2)/6)f3 + ((4kkk - 18kk + 22k - 6)/24)f4 + ((5kkkk - 40kkk + 105kk - 100k + 24)/120)f5 + ((6kkkkk - 75kkkk + 340kkk - 675kk + 548k - 120)/720)f6 )
  10. Calculate Second differentiation: fx_2 = (1/(hh)) * (f2 + (k-1)f3 + ((6kk - 18k + 11)/12)f4 + ((2kkk - 12kk + 21k - 10)/12)f5 + ((kkkk - 10kkk + 34kk - 45k + 18.27)/24)*f6)
  11. Print fx_1 and fx_2 as first and second differentiations respectively.
  12. Stop

PROGRAM :

#include<stdio.h> #include<conio.h> #include<math.h> void main() { float xi[10]; float fi[10][10]; int n; float x, x0, h, k; float f1,f2,f3,f4,f5,f6; float fx_1, fx_2; int i, j; printf("Enter the degree of polynomial: "); scanf("%d", &n); printf("Enter the data set of x:\n"); for(i=0;i<n;i++) { scanf("%f", &xi[i]); } printf("Enter the data set of f(x):\n"); for(i=0;i<n;i++) { scanf("%f", &fi[0][i]); } for(i=1;i<n;i++) { for(j=0;j<n-i;j++) { fi[i][j] = (fi[i-1][j+1]-fi[i-1][j]); } } printf("\nDivided difference table:\n"); printf("df\td2f\td3f\td4f\td5f\td6f\n"); for(j=0;j<n;j++) { for(i=1;i<n-j;i++) { printf("%.4f\t", fi[i][j]);

OUTPUT: