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
|
#include <iostream>
#include <cmath>
using namespace std;
// Note convergence restrictions: abs(x) < 1 and c not a negative integer or zero
double hypergeometric( double a, double b, double c, double x )
{
const double TOLERANCE = 1.0e-10;
double term = a * b * x / c;
double value = 1.0 + term;
int n = 1;
while ( abs( term ) > TOLERANCE )
{
a++, b++, c++, n++;
term *= a * b * x / c / n;
value += term;
}
return value;
}
//======================================================================
int main()
{
double a = 2.0, b = 3.0, c = 4.0;
double x = 0.5;
cout << "F( " << a << ", " << b << "; " << c << ", " << x << " ) = " << hypergeometric( a, b, c, x ) << '\n';
}
|