Logo 
Search:

C Programming Articles

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

LAGRANGE'S INTERPOLATION METHOD FOR FINDING X

Posted By: Holly Brown     Category: C Programming     Views: 5125

Write a program of LAGRANGE'S INTERPOLATION METHOD FOR FINDING X.

Code for LAGRANGE'S INTERPOLATION METHOD FOR FINDING X in C Programming

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
  float x[10],y[10],temp=1,f[10],sum,p;
  int i,n,j,k=0,c;
  clrscr();
  printf("\nhow many record you will be enter: ");
  scanf("%d",&n);
  for(i=0; i<n; i++)
  {
   printf("\n\nenter the value of x%d: ",i);
   scanf("%f",&x[i]);
   printf("\n\nenter the value of f(x%d): ",i);
   scanf("%f",&y[i]);
  }
  printf("\n\nEnter f(x) for finding x: ");
  scanf("%f",&p);

  for(i=0;i<n;i++)
  {
    temp = 1;
    k = i;
    for(j=0;j<n;j++)
    {
      if(k==j)
      {
        continue;
      }
      else
      {
        temp = temp * ((p-y[j])/(y[k]-y[j]));
      }
    }
    f[i]=x[i]*temp;
  }

  for(i=0;i<n;i++)
  {
     sum = sum + f[i];
  }
  printf("\n\n* * * x = %f * * *",sum);
  getch();
}


/*
______________________________________

OUT PUT
______________________________________


how many record you will be enter: 4


enter the value of x0: 20


enter the value of f(x0): 0.342


enter the value of x1: 25


enter the value of f(x1): 0.423


enter the value of x2: 30


enter the value of f(x2): 0.500


enter the value of x3: 35


enter the value of f(x3): 0.650


Enter f(x) for finding x: 0.390


* * * x = 22.840574 * * *


*/
  
Share: 


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

Holly Brown
Holly Brown author of LAGRANGE'S INTERPOLATION METHOD FOR FINDING X 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!