Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Numerical MethodsRSS Feeds

LAGRANGE'S INVERSE INTERPOLATION METHOD

Posted By: Aidan Evans     Category: C Programming     Views: 11773

LAGRANGE'S INVERSE INTERPOLATION METHOD.

Code for LAGRANGE'S INVERSE INTERPOLATION METHOD in C Programming

#include<stdio.h>
#include<conio.h>
#define MAX 10

void main()
{
    FILE *fp;
    int number,i,j;
    float xvalue[MAX],yvalue[MAX],search,product;
    float sum=0;
    fp=fopen("lgrninv.dat","w");
    clrscr();
    printf("\n\n");
    fprintf(fp,"\n\n");
    printf("How many numbers you want to enter for x  : ");
    fprintf(fp,"How many numbers you want to enter for x  : ");
    scanf("%d",&number);
    fprintf(fp,"%d",number);
    for(i=0;i<number;i++)
    {
        printf("\nEnter value for x(%d)  : ",i);
        fprintf(fp,"\nEnter value for x(%d)  : ",i);
        scanf("%f",&xvalue[i]);
        fprintf(fp,"%f",xvalue[i]);
        printf("\nEnter value for y(%d)  : ",i);
        fprintf(fp,"\nEnter value for y(%d)  : ",i);
        scanf("%f",&yvalue[i]);
        fprintf(fp,"%f",yvalue[i]);
    }
    printf("\nEnter any value of y for which you want to find x : ");
    fprintf(fp,"\nEnter any value of y for which you want to find x : ");
    scanf("%f",&search);
    fprintf(fp,"%f",search);
    for(i=0;i<number;i++)
    {
        product=1;
        for(j=0;j<number;j++)
        {
            if(i!=j)
            {
                product=product*(search-yvalue[j])/(yvalue[i]-yvalue[j]);
            }
        }
        sum=sum+xvalue[i]*product;
    }
    clrscr();
    printf("\n\n\n\n");
    fprintf(fp,"\n\n\n\n");
    printf("LAGRANGE'S INVERSE INTERPOLATION METHOD  ");
    fprintf(fp,"LAGRANGE'S INVERSE INTERPOLATION METHOD  ");
    printf("\n\n");
    fprintf(fp,"\n\n");
    printf("  X      Y   ");
    fprintf(fp,"  X      Y   ");
    printf("\n\n");
    fprintf(fp,"\n\n");
    for(i=0;i<number;i++)
    {
        printf("  %.2f   %.2f   ",xvalue[i],yvalue[i]);
        fprintf(fp,"  %.2f   %.2f   ",xvalue[i],yvalue[i]);
        printf("\n");
        fprintf(fp,"\n");
    }
    printf("\n\n");
    fprintf(fp,"\n\n");
    printf("Interpolated value is  :   %.4f  ",sum);
    fprintf(fp,"Interpolated value is  :   %.4f  ",sum);
    fclose(fp);
    getch();
}
  
Share: 

 
 
 

Didn't find what you were looking for? Find more on LAGRANGE'S INVERSE INTERPOLATION METHOD Or get search suggestion and latest updates.

Aidan Evans
Aidan Evans author of LAGRANGE'S INVERSE INTERPOLATION METHOD is from London, United Kingdom.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!