Wednesday, 23 April 2014

NEWTON DIVIDED DIFFERENCE FORMULA

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
#define n 5
int main()
{
    float y[n],x[n],d[n-1],xa,u,sum=0,tnum,tden;
    int i,j,l,k,m;
   // clrscr();
    printf("enter the values of interpolation x points\n");
    for(i=1;i<=n;i++)
    scanf("%f",&x[i]);
    printf("enter the corresponding values of y\n");
    for(i=1;i<=n;i++)
    scanf("%f",&y[i]);
    printf("enter the value of x at which y(x) is needed\n");
    scanf("%f",&xa);
    if(fabs(xa-x[1])>fabs(xa-x[n]))
    {
       printf("this is not a suitable formula\n");
         return(1);
     }
     m=n-1;
     for(i=1;i<n;i++)
                d[i]=y[i+1]-y[i];
                 for(i=2;i<n;i++)
                 {
                  for(l=i;i>l;l--)
                  printf("\t");
                   for(j=i;j<n;j++)
                   {
                   k=m-j+i;
                   d[k]=d[k]-d[k-1];
                   }
                   }
                   u=((xa-x[1])/fabs(x[2]-x[1]));
                   sum=y[1];
                   tnum=u;
                   tden=1.0;
                   for(i=1;i<n;i++)
                   {
                   sum=sum+(tnum/tden)*d[i];
                   tnum=tnum*(u-1);
                   tden=tden*(i+1);
                   }
                   printf("the value of y is %f\n",sum);
                   getch();

 }

No comments:
Write comments

Featured post

List of Universities in Karnataka offering M.Sc Computer Science

The post-graduate programme in Computer Science (M.Sc Computer Science) contains two academic years duration and having a four semesters....

Popular Posts

Copyright @ 2011-2016