• Recent Uploads

    NEWTON'S FORWORD INTERPOLATION METHOD IN C LANGUAGE

    Newton Forward.Interpolation is the technique of estimating the value of a function for any intermediate value of the independent variable, while the process of computing the value of the function outside the given range is called extrapolation.


    //this method is for 5 elements 
    
    #include <stdio.h>
    
    #include <stdlib.h>
    
    
    
    int main()
    
    {
    
        int i,x[10],y[10],temp[10],temp1[10],temp2[10],temp3[10],m,y0,y1,y2,y3;
    
        float o, w,u,p,a,h;
    
        int m=4;
    
        printf("enter the elemets of x");
    
        for(i=0;i<=m;i++)
    
        {
    
        scanf("%d",&x[i]);
    
        }
    
        printf("enter the elements of y");
    
        for(i=0;i<=m;i++)
    
        {
    
            scanf("%d",&y[i]);
    
        }
    
        printf("\n first difference");
    
        for(i=0;i<=m-1;i++)
    
        {
    
        temp[i]=y[i+1]-y[i];
    
           printf("\n%d",temp[i]);
    
        if(i==0)
    
        {
    
            y0=temp[i];
    
            printf("\nthe last element =%d",y0);
    
        }
    
    
    
    
    
        }
    
        printf("\nsecond difference");
    
        for(i=0;i<=m-2;i++)
    
        {
    
            temp1[i]=temp[i+1]-temp[i];
    
    
    
            printf("\n%d",temp1[i]);
    
            if(i==0)
    
            {
    
                y1=temp1[i];
    
                  printf("\nthe last element of 2nd differnce =%d",y1);
    
            }
    
        }
    
        printf("\n3rd difference ");
    
        for(i=0;i<=m-3;i++)
    
        {
    
            temp2[i]=temp1[i+1]-temp1[i];
    
    
    
            printf("\n%d",temp2[i]);
    
            if(i==0)
    
            {
    
                y2=temp2[i];
    
                  printf("\nthe last element =%d",y2);
    
            }
    
             }
    
             printf("\n 4th differnce :-");
    
             for(i=0;i<=m-4;i++)
    
             {
    
                 temp3[i]=temp2[i+1]-temp2[i];
    
    
    
                 printf("\n%d",temp3[i]);
    
                 if(i==0)
    
                 {
    
                     y3=temp3[i];
    
                     printf("\nthe last element=%d",y3);
    
                 }
    
             }
    
             printf("\n enter the value of x");
    
             scanf("%f",&p);
    
             printf("\n enter the value of a and h");
    
             scanf("%f%f",&a,&h);//WHERE a is the first value
    
             u=(p-a)/h;
    
             printf("\n u=%f",u);
    
             printf("enter the vlaue of y0 ");
    
             scanf("%f",&o);
    
    
    
             printf("\n the final answer is");
    
             w=o+(u*y0)+(u*(u-1)*y1)/2+(u*(u-1)*(u-2)*y2)/6+(u*(u-1)*(u-2)*(u-3)*y3)/24;//newton forward formula
    
             printf("\n w=%f",w);
    
        return 0;
    
    }



    Output:








      Dear Visitors! If you are facing any problem, If you have any question or suggestion Please Comment Us.

      **** WE THANKFUL TO VISITORS****
      PLZ... Share This Site To Your Contacts.....


                                                                                                                With warm regards


                                                                                                                                           TEAM EveTech