根据您发布的wiki文章,我认为您可以使用我编写的以下代码近似超几何函数的值:
作为下一步,可以估计近似值的误差。
/**
* The generalized hypergeometric function is a convergent power series \sum_{i=0}^{\infty} c_i x^i
* where the coefficients satisfy c_{n+1}/c_n = A(n)/B(n) for some polynomials A and B in n.
* It is customary to factor out the leading term, so c_0 is assumed to be 1
*/
public class HypergeometricFunction {
private final int degreeOfApproximation;
private final double[] coefficientsOfA;
private final double[] coefficientsOfB;
private final double[] coefficientsOfHypergeometricFunction;
public HypergeometricFunction(int degreeOfApproximation, double[] coefficientsOfA, double[] coefficientsOfB) {
this.degreeOfApproximation = degreeOfApproximation;
this.coefficientsOfA = coefficientsOfA;
this.coefficientsOfB = coefficientsOfB;
this.coefficientsOfHypergeometricFunction = generateCoefficients();
}
/**
* @param x input
* @return Approximation to the hypergeometric function by taking the first
* {@code degreeOfApproximation} terms from the series.
*/
public double approximate(double x){
return evaluatePolynomial(x, coefficientsOfHypergeometricFunction);
}
private double[] generateCoefficients() {
double[] coefficients = new double[degreeOfApproximation];
coefficients[0] = 1;
for (int i = 1; i < degreeOfApproximation; i++)
coefficients[i] = (evaluatePolynomial(i, coefficientsOfA) / evaluatePolynomial(i, coefficientsOfB)) * coefficients[i - 1];
return coefficients;
}
private double evaluatePolynomial(double n, double[] coefficients) {
int length = coefficients.length;
double out = 0.0D;
for (int i = 0; i < length; i++) {
out += coefficients[i] * pow(n, i);
}
return out;
}
private double pow(double a, int b) {
double out = 1;
for (int i = 0; i < b; i++) out *= a;
return out;
}
}
如果序列收敛(因此提供了适当的超几何函数),则必须为零,因此,如果您认为足够大,这应该提供合理的近似值。lim[c_i*x^i]
degreeOfApproximation
多项式 A 和 B 是 wiki 文章中提到的多项式,为了使用此代码,您必须向构造函数提供这些多项式的系数数组,以及所需的近似程度。
希望这对您有所帮助。