I am trying to compute the value of Beta function for complex argument. The method scipy.special.beta
does not accept complex argument, so I defined instead
beta = lambda a, b: (gamma(a) * gamma(b)) / gamma(a + b)
It works fine for small values, however, for large values, it would return nan
. So I digged into the behaviour of Gamma function
from scipy.special import gamma
import numpy
radius = 165
phi = (3.0 * numpy.pi) / 4.0
n = 1.9 + numpy.exp(phi * 1j) * radius
print gamma(n)
A 0j
will be returned and clearly the value is too small to be printed.
However, though the value of the Gamma function is super small, the value of the corresponding Beta function is not quite. So it still makes sense to do the calculation. But I could not figure out a way.
I tried math.gamma
, but it would not accept complex argument. I tried the method provided in this answer, it would return -0j
for
n = 1.9 + numpy.exp(phi * 1j) * radius
numpy.exp(numpy.log(gamma(n)) + numpy.log(gamma(0.5)) - numpy.log(gamma(n + 0.5)))
where I was trying to compute beta(n, 0.5).
Could someone please help me on this issue? Thanks in advance!
I don't know about scipy, but you could use sympy for the evaluation of the beta function. It supports complex arguments. This documentation might help you with that.
So your code would roughly look like this if I understood you correctly:
from sympy.functions.special.beta_functions import beta
import numpy
radius = 165
phi = (3.0 * numpy.pi) / 4.0
n = 1.9 + numpy.exp(phi * 1j) * radius
print(beta(n, 0.5))
>>> 0.0534468376932947 - 0.127743871500741*I