Skip to content

Commit

Permalink
Merge pull request scipy#9055 from akahard2dj/DOC_scipy.special.erf_f…
Browse files Browse the repository at this point in the history
…amily

DOC: Add examples to scipy.special docstrings
  • Loading branch information
pvanmulbregt authored Oct 20, 2018
2 parents 8364b36 + 68ec121 commit af721d2
Showing 1 changed file with 98 additions and 3 deletions.
101 changes: 98 additions & 3 deletions scipy/special/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,19 +754,113 @@ def riccati_yn(n, x):


def erfinv(y):
"""Inverse function for erf.
"""Inverse of the error function erf.
Computes the inverse of the error function.
In complex domain, there is no unique complex number w satisfying erf(w)=z.
This indicates a true inverse function would have multi-value. When the domain restricts to the real, -1 < x < 1,
there is a unique real number satisfying erf(erfinv(x)) = x.
Parameters
----------
y : ndarray
Argument at which to evaluate. Domain: [-1, 1]
Returns
-------
erfinv : ndarray
The inverse of erf of y, element-wise
Examples
--------
1) evaluating a float number
>>> from scipy import special
>>> special.erfinv(0.5)
0.4769362762044698
2) evaluating a ndarray
>>> from scipy import special
>>> y = np.linspace(-1.0, 1.0, num=10)
>>> special.erfinv(y)
array([ -inf, -0.86312307, -0.5407314 , -0.30457019, -0.0987901 ,
0.0987901 , 0.30457019, 0.5407314 , 0.86312307, inf])
"""
return ndtri((y+1)/2.0)/sqrt(2)


def erfcinv(y):
"""Inverse function for erfc.
"""Inverse of the complementary error function erfc.
Computes the inverse of the complementary error function erfc.
In complex domain, there is no unique complex number w satisfying erfc(w)=z.
This indicates a true inverse function would have multi-value. When the domain restricts to the real, 0 < x < 2,
there is a unique real number satisfying erfc(erfcinv(x)) = erfcinv(erfc(x)).
It is related to inverse of the error function by erfcinv(1-x) = erfinv(x)
Parameters
----------
y : ndarray
Argument at which to evaluate. Domain: [0, 2]
Returns
-------
erfcinv : ndarray
The inverse of erfc of y, element-wise
Examples
--------
1) evaluating a float number
>>> from scipy import special
>>> special.erfcinv(0.5)
0.4769362762044698
2) evaluating a ndarray
>>> from scipy import special
>>> y = np.linspace(0.0, 2.0, num=11)
>>> special.erfcinv(y)
array([ inf, 0.9061938 , 0.59511608, 0.37080716, 0.17914345,
-0. , -0.17914345, -0.37080716, -0.59511608, -0.9061938 ,
-inf])
"""
return -ndtri(0.5*y)/sqrt(2)


def erf_zeros(nt):
"""Compute nt complex zeros of error function erf(z).
"""Compute the first nt zero in the first quadrant, ordered by absolute value.
Zeros in the other quadrants can be obtained by using the symmetries erf(-z) = erf(z) and
erf(conj(z)) = conj(erf(z)).
Parameters
----------
nt : int
The number of zeros to compute
Returns
-------
The locations of the zeros of erf : ndarray (complex)
Complex values at which zeros of erf(z)
Examples
--------
>>> from scipy import special
>>> special.erf_zeros(1)
array([1.45061616+1.880943j])
Check that erf is (close to) zero for the value returned by erf_zeros
>>> special.erf(special.erf_zeros(1))
array([4.95159469e-14-1.16407394e-16j])
References
----------
Expand Down Expand Up @@ -2181,3 +2275,4 @@ def zeta(x, q=None, out=None):
if q is None:
q = 1
return _zeta(x, q, out)

0 comments on commit af721d2

Please sign in to comment.