betaincinv¶
- mpsci.fun.betaincinv(a, b, y, method='findroot', complement=False)¶
Inverse of the regularized incomplete beta function.
If
complementis True, the inverse of the complement of the regularized incomplete beta function is computed.The function name and first three parameters match those of
scipy.special.betaincinv. Withcomplement=True, the function computes the equivalent ofscipy.special.betainccinv.The
methodparameter has several options:"findroot":Use
mpmath.mp.findroot, with initial guess 0.5.
("findroot", x0):Use
mpmath.mp.findroot, with initial guessx0.
"bisect":Use a bisection method, starting with the root bracket [0, 1].
("bisect", [xa, xb]):Use a bisection method; start the bisection with the bracket
[xa, xb].xaandxbmust be chosen so that the inverse is in the interval[xa, xb].
The numerical method that is used to find the root (either
mpmath.mp.findrootor the bisection method) might fail for some inputs. If that happens, try changing the method, or try changing the initial guess or initial bracket.Examples
>>> from mpmath import mp >>> from mpsci.fun import betaincinv
>>> mp.dps = 125 >>> a = mp.mpf('0.001') >>> b = mp.mpf(2500) >>> y = mp.mpf('0.995')
>>> x = betaincinv(a, b, y, method='bisect) >>> with mp.workdps(50): ... print(x) 0.0000015015140517221501171052646134215218978294984794701
Verify the inverse:
>>> y1 = mp.betainc(a, b, 0, x, regularized=True) >>> with mp.workdps(50): ... print(y1) ... 0.995