Is there a scaled complementary error function in python available?

前端 未结 5 1826
心在旅途
心在旅途 2021-01-18 03:54

In matlab there is a special function which is not available in any of the collections for the Python I know (numpy, scipy, mpmath, ...).

Probably there are other p

5条回答
  •  心在旅途
    2021-01-18 04:17

    Here is a simple and fast implementation giving 12-13 digit accuracy globally:

    from scipy.special import exp, erfc
    
    def erfcx(x):
        if x < 25:
            return erfc(x) * exp(x*x)
        else:
            y = 1. / x
            z = y * y
            s = y*(1.+z*(-0.5+z*(0.75+z*(-1.875+z*(6.5625-29.53125*z)))))
            return s * 0.564189583547756287
    

提交回复
热议问题