mx02 //lagrange Interpolation // (1,12.8), (2,19.6), (3, 28.5), (4, 40.2) // Approximate F at X 2.4
mx02 //lagrange Interpolation // (1,12.8), (2,19.6), (3, 28.5), (4, 40.2) // Approximate F at X 2.4
//lagrange interpolation
//(1,12.8), (2,19.6), (3, 28.5), (4, 40.2)
// approximate f at x = 2.4
#include<stdio.h>
#include<math.h>
int main()
{
float x[10], y[10], temp=1, f[10], sum, p;
int i,n,j,k=0;
printf("Enter the no. of data points: ");
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 the the value of x to approximate the value of f(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-x[j])/(x[k]-x[j]));
}
}
f[i] = y[i] * temp;
}
for(i=0;i<n;i++)
{
sum = sum + f[i];
}