How can I implement the Gaussian Hypergeometric Function 2F1(a, b, c, z) in C#, with the ability on handling negative and large z values?
2F1 is part of the integral of a certain equation resulting in the following implementation:
internal static double HCWR(double distance, double n)
{
double geometricResult = 2F1(1, 1 / n, 1 + 1 / n, -Math.Pow(distance, -n));
return (Math.Pow(distance, -n) * geometricResult);
}
n can be any number bigger or equal to 2 and distance can be any number in the interval (0,1].
Values like a = 1, b = 0.5, c = 1.5 and z = -25.0, which should be 0.27468, aren’t handled well in every implementation. CenterSpace refuses every |z| > 1 and MathNet.Numerics returns -infinity, while I prefer an implementation that can handle non-integer values for z.