1
$\begingroup$

I am working with functions like

f[z_] = Hypergeometric2F1[4, 4, 8, z]

Here is a plot of this function over the interval $z \in [0,1]$:

plot of the function in the interval (0,1)

Plot[f[z], {z, 0, 1}]

As you can see, Mathematica has difficulties evaluating it in the region $z \approx 0$. This is surprising, because the hypergeometric function admits by definition a simple series expansion around $z = 0$, $$ f(z) = \sum_{n = 0}^\infty \frac{7!}{(3!)^2} \frac{(n+1)(n+2)(n+3)}{(n+4)(n+5)(n+6)(n+7)} z^n = 1 + 2 z + \frac{25}{9} z^2 + \ldots $$

The problem is that Mathematica does not use this defining property of the hypergeometric function, but instead it "simplifies" it to

f[z] = (140*(-60*z + 60*z^2 - 11*z^3 - 60*Log[1 - z] + 90*z*Log[1 - z] - 36*z^2*Log[1 - z] + 3*z^3*Log[1 - z]))/(3*z^7)

and it turns out that cancellations between large numbers occur in this expression when $z \approx 0$.

How can I instruct mathematica to not perform this "simplification" in general? Is there a way I can use the command Hold or something similar?

What I want to do eventually is evaluate numerically some integrals in which $f(z)$ appears in the integrand, so I need a robust way of evaluating the function over the interval $z \in [0,1]$.

$\endgroup$
  • 5
    $\begingroup$ The symbolic calculation can be stopped by f[z_] := Hypergeometric2F1[4, 4, 8, z] or more strictly Clear[f]; f[z_?NumericQ] := Hypergeometric2F1[4, 4, 8, z], but these solutions may not be suitable for the real problem. I think it's better to make the question more specific e.g. show an integral you want to calculate. (The integral should be simplified as much as possible of course. ) BTW somewhat related: mathematica.stackexchange.com/q/117888/1871 $\endgroup$ – xzczd Mar 12 at 15:57
  • 2
    $\begingroup$ Your function can be expressed in terms of the Legendre function of the second kind. You could try reformulating in terms of LegendreQ[]. $\endgroup$ – J. M. will be back soon Mar 12 at 15:59
  • $\begingroup$ @J.M.isslightlypensive, the Legendre functions get auto-expanded in the same way: the relevant one here is LegendreQ[3, 1 - 2/z], which automatically becomes $-\frac{10}{x^2}+\frac{\left(1-\frac{2}{x}\right) \left(x^2-10 x+10\right) \left(\frac{1}{2} \log \left(2-\frac{2}{x}\right)-\frac{1}{2} \log \left(\frac{2}{x}\right)\right)}{x^2}+\frac{10}{x}-\frac{11}{6}$ upon evaluation and then has the same numerical issues. $\endgroup$ – Roman Mar 13 at 10:50
1
$\begingroup$

The commands

Plot[Hypergeometric2F1[4, 4, 8, z], {z, 0, 1}, WorkingPrecision -> 15]

or/and

f[z_] = Hypergeometric2F1[4, 4, 8, z]; Plot[f[z], {z, 0, 1}, WorkingPrecision -> 25]

do the job.

Addition.

Integrate[Hypergeometric2F1[4, 4, 8, z], {z, 0, 1}]

$\frac{133}{9} $

NIntegrate[Hypergeometric2F1[4, 4, 8, z], {z, 0, 1}, WorkingPrecision -> 15]

$14.7777777777777 $

$\endgroup$
0
$\begingroup$

I'm not sure if this will help, but it might be worth checking out.

f[z_] = Hypergeometric2F1[4, 4, 8, z] // FunctionExpand
(*(140 (-(11 z^3) + 3 z^3 Log[1 - z] + 60 z^2 - 36 z^2 Log[1 - z] - 
   60 z + 90 z Log[1 - z] - 60 Log[1 - z]))/(3 z^7)*)

<< PrecisionPlot`

PrecisionPlot[f[z], {z, 0, 1}]

enter image description here

You can get PrecisionPlot from http://library.wolfram.com/infocenter/MathSource/715/

The problem seems to be precision rather than the function Mathematica uses. Compare:

f[1/1000] // N
(*2.47395*10^8*)

with

f[1/1000] // N[#, 50] &
(*1.0020027811148271960352800702800453256995763414200*)

and while f[0] doesn't work, the limit does.

Limit[f[z], z -> 0]
(*1*)

Although PrecisionPlot is smoother, it doesn't really do a great job of matching the very small values of z.

$\endgroup$
  • 1
    $\begingroup$ PrecisionPlot[] was useful back in the day when Plot[] did not have the WorkingPrecision option; nowadays, the built-in function is adequate. $\endgroup$ – J. M. will be back soon Mar 13 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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