Newtons Lagrange Method
// Online C compiler to run C program online
#include <stdio.h>
int main() {
float x[10],y[10],sum1 = 1,sum2 = 0,xi;
int i,j,n;
printf("Enter the number of x:");
scanf("%d",&n);
printf("Enter the x values");
for(i = 0;i<n;i++){
scanf("%f",&x[i]);
}
printf("Enter the y values");
for(i = 0;i<n;i++){
scanf("%f",&y[i]);
}
printf("Enter value to be interpolated:");
scanf("%f",&xi);
for(i = 0;i<n;i++){
sum1 = 1;
for(j = 0;j<n;j++){
if(j != i){
sum1 *= xi-x[j];
sum1 /= (x[i] - x[j]);
}
}
sum2 += (sum1 * y[i]);
}
printf("Interpolated value = %f",sum2);
return 0;
}
Tags:
SY