6
$\begingroup$

I need an efficient and accurate method to evaluate hypergeometric ratios of the form:

$$\frac{_{2}F_{1}(a+1,b;c;x)}{_{2}F_{1}(a,b;c;x)}$$

for large positive values of a, b, c. However, if you plot:

Plot[Hypergeometric2F1Regularized[601, Rationalize[100.1], 100, x]/
     Hypergeometric2F1Regularized[600, Rationalize[100.1], 100, x], {x, 0, 1}]

you will see that these ratios can be inaccurate in Mathematica.

What can I do?

$\endgroup$
0

2 Answers 2

4
$\begingroup$

Using N on exact input avoids the round-off error from calculating the two hypergeometric functions separately. (I stopped before x = 1, since that produces a divide-by-zero error.)

ListLinePlot@
 N@Table[Hypergeometric2F1Regularized[601, Rationalize[100.1], 100, x] / 
         Hypergeometric2F1Regularized[600, Rationalize[100.1], 100, x],
   {x, 0, 1 - 1/100, 1/100}]

Mathematica graphics

Alternatively, one could use a relatively high WorkingPrecision:

Plot[Hypergeometric2F1Regularized[601, Rationalize[100.1], 100, x] /
     Hypergeometric2F1Regularized[600, Rationalize[100.1], 100, x],
 {x, 0, 1}, WorkingPrecision -> 50]

(Pretty much the same graph as above.)

$\endgroup$
2
  • $\begingroup$ Michael, I know this is old, and sorry for the noob question, but can you please elaborate on this 'divide by zero' error you talk about, with variable = 1 (exactly)? $\endgroup$
    – 299792458
    Jun 17, 2020 at 8:51
  • $\begingroup$ @299792458 I'm referring to the fact that Hypergeometric2F1Regularized[600, Rationalize[100.1], 100, 1] throws a divide by zero error (Power::infy). $\endgroup$
    – Michael E2
    Jun 17, 2020 at 14:01
2
$\begingroup$

Using one of the three-term recurrences satisfied by ${}_2 F_1$, and exploiting the fact that $a$ and $c$ are integers, here is an implementation of the continued fraction expansion of the hypergeometric function ratio in the OP:

ratio2f1[a_Integer?Positive, b_, c_Integer?Positive, z_] :=
     ((a (z - 2) - b z + c)/a +
      ContinuedFractionK[(a - k - c)/(a - k) (z - 1),
                         ((a - k - 1) (z - 2) - b z + c)/(a - k - 1),
                         {k, 0, a - 2}])/(z - 1)

This implementation is now quite stable for plotting purposes:

Plot[{Hypergeometric2F1Regularized[601, 1001/10, 100, x]/
      Hypergeometric2F1Regularized[600, 1001/10, 100, x],
      ratio2f1[600, 1001/10, 100, x]}, {x, 0, 1}, 
     PlotStyle -> {AbsoluteThickness[5], AbsoluteThickness[2]}]

plot of hypergeometric function ratio, explicit vs. CF


Let me also present an alternative implementation that avoids using ContinuedFractionK[], which may be useful for e.g. making a compiled function. I used the Lentz-Thompson-Barnett algorithm to evaluate the continued fraction:

ratio2f1[a_Integer?Positive, b_, c_Integer?Positive, z_] := Module[{ak, bk, ck, dk, f},
     f = ck = (a (z - 2) - b z + c)/a; dk = 0;
     Do[ak = (a - k - c)/(a - k) (z - 1); 
        bk = ((a - k - 1) (z - 2) - b z + c)/(a - k - 1);
        dk = 1/(bk + ak dk); ck = bk + ak/ck; f *= ck dk,
        {k, 0, a - 2}];
     f/(z - 1)]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.