-
Notifications
You must be signed in to change notification settings - Fork 0
/
LAGRANGER.c
42 lines (40 loc) · 872 Bytes
/
LAGRANGER.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// LAGRANGE INTERPOLATION METHOD
#include <stdio.h>
#include <stdio.h>
#include <math.h>
int main()
{
printf("LAGRANGE METHOD\n");
int n;
float a;
printf("Enter the number of user-input data\n");
scanf("%d", &n);
float x[n];
float y[n];
printf("Enter the value of x for which f(x) is to be evaluated\n");
scanf("%f", &a);
int i, i1, j;
float k, s;
s = 0;
for (i = 0; i < n; i++)
{
printf("Enter x%d\n", (i + 1));
scanf("%f", &x[i]);
printf("Enter fx(%d)\n", (i + 1));
scanf("%f", &y[i]);
}
for (j = 0; j < n; j++)
{
k = y[j];
for (i1 = 0; i1 < n; i1++)
{
if (i1 != j)
{
k = k * ((a - x[i1]) / (x[j] - x[i1]));
}
}
s = s + k;
}
printf("f(%f)=%f\n", a, s);
return 0;
}