-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLGII.cpp
More file actions
61 lines (56 loc) · 1.3 KB
/
LGII.cpp
File metadata and controls
61 lines (56 loc) · 1.3 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
#include <iostream>
#include <stdlib.h>
//#include "comp_x.cpp"
typedef double Real;
using namespace std;
// Page for Lagrauge's Inverse Interpolation Formula
void LGII(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 x= ";
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<<")";
if(i!=(n-1))
cout<<" + ";
}
cout<<"\nTherefore \n y|(x="<<yv<<") = "<<xv<<" ans"<<endl;
}
int LGII_main()
{
//system("clscr");
int n=0;
Real xv=0;
cout <<" Lagrauge's Inverse 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 y for which x to be found to be found : ";
cin>>xv;
LGII(y,x,n,xv);
return 0;
}