-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLGIF.cpp
More file actions
63 lines (58 loc) · 1.36 KB
/
LGIF.cpp
File metadata and controls
63 lines (58 loc) · 1.36 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <stdlib.h>
#include "comp_x.cpp"
typedef double Real;
using namespace std;
// Lagrauge's Interpolation Formula
/**here x points towards x array, y points towards y array and n is their size**/
void LGIF(Real *x, Real *y, int n, Real xv)
{
cout<<" x :";
for(int i=0;i<n;i++)
{
cout<<x[i]<<"\t";
}
cout<<"\n";
cout<<" y :";
for(int i=0;i<n;i++)
{
cout<<y[i]<<"\t";
}
cout<<"\n\n\n"; //some line breakes for good output
// formula to calculate the y(x)
Real yv=0,ya=0,yb=0;
cout<<"BY LGFI \n y|(x="<<xv<<") = ";
for(int i=0;i<n;i++)
{ ya=comp_x_a(x,xv,n,i);
yb=comp_x_b(x,x[i],n);
yv=yv+((ya*y[i])/yb);
cout<<ya<<"*"<<y[i]<<"/"<<yb;
//cout<<yv;
if(i!=(n-1))
cout<<" + ";
}
cout<<"\nTherefore \n y|(x="<<xv<<") = "<<yv<<" ans"<<endl;
}
int LGIF_main()
{
//system("clscr");
int n=0;
Real xv=0;
cout <<" Lagrauge's Interpolation Formula \nEnter the Number of elements : ";
cin>>n;
Real x[n],y[n];
cout<<"\nEnter the values of x \n:";
for(int i=0;i<n;i++)
{
cin>>x[i];
}
cout<<"\nEnter the values of y \n:";
for(int i=0;i<n;i++)
{
cin>>y[i];
}
cout<<"\nEnter the value of x to be found : ";
cin>>xv;
LGIF(x,y,n,xv);
return 0;
}