using System;
class GFG
{
class Data
{
public double x, y;
public Data(double x, double y)
{
this.x = x;
this.y = y;
}
};
static double inv_interpolate(Data []d,
int n, double y)
{
double x = 0;
int i, j;
for (i = 0; i < n; i++)
{
double xi = d[i].x;
for (j = 0; j < n; j++)
{
if (j != i)
{
xi = xi * (y - d[j].y) /
(d[i].y - d[j].y);
}
}
x += xi;
}
return x;
}
public static void Main(string[] args)
{
Data []d = {new Data(1.27, 2.3),
new Data(2.25, 2.95),
new Data(2.5, 3.5),
new Data(3.6, 5.1)};
int n = 4;
double y = 4.5;
Console.Write("Value of x at y = 4.5 : {0:f5}");
Console.Write(inv_interpolate(d, n, y));
}
}
What I have tried:
using System;
class GFG
{
class Data
{
public double x, y;
public Data(double x, double y)
{
this.x = x;
this.y = y;
}
};
static double inv_interpolate(Data []d,
int n, double y)
{
double x = 0;
int i, j;
for (i = 0; i < n; i++)
{
double xi = d[i].x;
for (j = 0; j < n; j++)
{
if (j != i)
{
xi = xi * (y - d[j].y) /
(d[i].y - d[j].y);
}
}
x += xi;
}
return x;
}
public static void Main(string[] args)
{
Data []d = {new Data(1.27, 2.3),
new Data(2.25, 2.95),
new Data(2.5, 3.5),
new Data(3.6, 5.1)};
int n = 4;
double y = 4.5;
Console.Write("Value of x at y = 4.5 : {0:f5}");
Console.Write(inv_interpolate(d, n, y));
}
}