Lecture08: Lagrange Interpolation by C language | Numerical Analysis

preview_player
Показать описание
This video is made for my classmates of Dept. of Mathematics, RU, who are facing troubles to prepare themselves for Lab Exam.
Рекомендации по теме
Комментарии
Автор

#include <stdio.h>
#include<math.h>

int main()
{
float F(float, float x[], int, int);
int i, j, n;
float u, sum=0.0, x[10], y[10];
printf("Enter no. of points ");
scanf("%d", &n);
printf("Enter the array x\n");
for(i=0;i<n;++i){
scanf("%f", &x[i]);
}
printf("Enter the array y\n");
for(i=0;i<n;++i){
scanf("%f", &y[i]);
}
printf("Enter the value of x for interpolation\n");
scanf("%f", &u);
for(i=0;i<n;++i){
sum=sum+(F(u, x, n, i)*y[i])/F(x[i], x, n, i);
}
printf("Interpolated value y=%f\n", sum);
return 0;
}

float F(float u, float x[], int n, int j)
{
float prod = 1;
for(int i=0;i<n;++i){
if (i==j) continue;
prod=prod*(u-x[i]);
}
return(prod);
}

kbwsoikat