Wednesday, October 1, 2014

Implement Newton’s backward interpolation polynomial using C programming.

#include
#include
void main()
{
            clrscr();
            int i,j,n,k;
            float f[30],x[30],df[30][30],xx,a,b,mul,ad,x0,f0;
            printf ("\t\tNewton's Backward Interpolation\n");
            printf ("\t\t------------------------------\n\n");
            printf("How many points???");
            scanf("%d",&n);
            for(i=0;i
            {
                        printf("\nEnter the value of x[%d]:",i);
                        scanf("%f",&x[i]);
                        printf("Enter the value of f[x%d]:",i);
                        scanf("%f",&f[i]);
                        df[0][i]=f[i];
            }
            printf("\n Enter the value x:");
            scanf("%f",&xx);
            a=x[1]-x[0];
            for(i=0;i
            {
                        df[i][1]=f[i+1]-f[i];

            }
            for(j=2;j
            {
                        for(i=0;i
                        {
                                    df[i][j]=df[i+1][j-1]-df[i][j-1];
                        }
            }
            i=0;
            while (!x[i]>xx)
            {
            i++;
            }
            x0=x[0];
            f0=f[0];
            b=(xx-x0)/a;
            mul=1;
            ad=f0;
            for(k=1;k<=n;k++)
            {
                        mul=(mul*(b-(k-1)))/k;
                        ad=ad+(mul*df[i][k]);
            }
            printf("\n The required value = %4f",ad);
            getch();

}

1 comment: