I would like to create a C# method that accepts a dictionary object (say, of type <int, double>
) that contains known values and a query value in such a way that an equation can be generated from the dictionary and the query value is looked up to return an interpolated value.
As a mock:
public double ReturnValue(Dictionary<int, double>, int queryValue)
{
// Generates an equation (e.g. in the form of y = mx + c) based on the dictionary object values
// Looks up y based on queryValue as an input in the variable x
return y;
}
Creating dynamic formula - This looks like what I am aftering, but it seems a bit too complicated for my case.
Any advice is appreciated - thank you.
Update: An example of a dictionary object:
var temperatureDic = new Dictionary<int, double>()
{
{ 0, 1.10},
{ 5, 1.06},
{ 10, 1.03 },
{ 15, 1.00 },
{ 20, 0.97 },
{ 25, 0.93 },
{ 30, 0.89 },
{ 35, 0.86 },
{ 40, 0.82 },
{ 45, 0.77 }
};