Thursday, January 11, 2018

Newton's Divided Difference Interpolation Method Program

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int n,i,j;
    float xvalue,x[10],a[10],fx[10],summation,p;
    printf("Saroj Rana\nRoll:37\tSem:3rd\n");
    printf("Enter number of points:");
    scanf("%d",&n);
    printf("Enter the value for x:");
    scanf("%f",&xvalue);
    for(i=0;i<n;i++){
       printf("Enter the value of x and fx at i=%d\n",i);
       scanf("%f%f",&x[i],&fx[i]);
         }
         for(i=0;i<n;i++){
           a[i]=fx[i];
         }
         for(i=0;i<n;i++){
           for(j=n;j>i;j--){
               a[j]=(a[j]-a[j-1])/(x[j]-x[j-1-i]);
           }
         }
         summation=0;
         for(i=0;i<n;i++){
           p=1;
           for(j=0;j<=i-1;j++){
               p=p*(xvalue-x[j]);

           }
           summation=summation+a[i]*p;
         }
         printf("Required value is %f",summation);
   return 0;

}

No comments:

Post a Comment