Lagrange's Interpolation Formula :



#include<stdio.h>
int main()
{
    int i,j,n,o;
    printf("Enter the value of n");
    scanf("%d",&n);
    float x[n],y[n],u,d,w,r;
    for(i=0;i<n;i++)
        {
    printf("Enter the value of x[%d]",i);
         scanf("%f",&x[i]);
        }
        for(i=0;i<n;i++)
        {
    printf("Enter the value of y[%d]",i);
         scanf("%f",&y[i]);
        }

    r=0;
    printf("Enter the number whose approximate value you want");
    scanf("%f",&w);
    for(i=0;i<n;i++)
    {
        u=d=1;
        for(j=0;j<n;j++)
        {
            if(j!=i)
            {
            u=u*(w-x[j]);
            d=d*(x[i]-x[j]);
            }
        }
        r=r+((u/d)*y[i]);
    }
    printf("The output is %f",r);
    return 0;
}

Comments

Popular posts from this blog

Newton Backward Interpolation Formula