當前位置: 首頁>>代碼示例>>Python>>正文


Python mpmath.sqrt方法代碼示例

本文整理匯總了Python中mpmath.sqrt方法的典型用法代碼示例。如果您正苦於以下問題:Python mpmath.sqrt方法的具體用法?Python mpmath.sqrt怎麽用?Python mpmath.sqrt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在mpmath的用法示例。


在下文中一共展示了mpmath.sqrt方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_ladder_operator_coefficient

# 需要導入模塊: import mpmath [as 別名]
# 或者: from mpmath import sqrt [as 別名]
def test_ladder_operator_coefficient():
    # for ell in range(sf.ell_max + 1):
    #     for m in range(-ell, ell + 1):
    #         a = math.sqrt(ell * (ell + 1) - m * (m + 1))
    #         b = sf.ladder_operator_coefficient(ell, m)
    #         if (m == ell):
    #             assert b == 0.0
    #         else:
    #             assert abs(a - b) / (abs(a) + abs(b)) < 3e-16
    for twoell in range(2*sf.ell_max + 1):
        for twom in range(-twoell, twoell + 1, 2):
            a = math.sqrt(twoell * (twoell + 2) - twom * (twom + 2))/2
            b = sf._ladder_operator_coefficient(twoell, twom)
            c = sf.ladder_operator_coefficient(twoell/2, twom/2)
            if (twom == twoell):
                assert b == 0.0 and c == 0.0
            else:
                assert abs(a - b) / (abs(a) + abs(b)) < 3e-16 and abs(a - c) / (abs(a) + abs(c)) < 3e-16 
開發者ID:moble,項目名稱:spherical_functions,代碼行數:20,代碼來源:test_spherical_functions.py

示例2: compute_a

# 需要導入模塊: import mpmath [as 別名]
# 或者: from mpmath import sqrt [as 別名]
def compute_a(n):
    """a_k from DLMF 5.11.6"""
    a = [mp.sqrt(2)/2]
    for k in range(1, n):
        ak = a[-1]/k
        for j in range(1, len(a)):
            ak -= a[j]*a[-j]/(j + 1)
        ak /= a[0]*(1 + mp.mpf(1)/(k + 1))
        a.append(ak)
    return a 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:12,代碼來源:gammainc_asy.py

示例3: compute_g

# 需要導入模塊: import mpmath [as 別名]
# 或者: from mpmath import sqrt [as 別名]
def compute_g(n):
    """g_k from DLMF 5.11.3/5.11.5"""
    a = compute_a(2*n)
    g = []
    for k in range(n):
        g.append(mp.sqrt(2)*mp.rf(0.5, k)*a[2*k])
    return g 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:9,代碼來源:gammainc_asy.py

示例4: eta

# 需要導入模塊: import mpmath [as 別名]
# 或者: from mpmath import sqrt [as 別名]
def eta(lam):
    """Function from DLMF 8.12.1 shifted to be centered at 0."""
    if lam > 0:
        return mp.sqrt(2*(lam - mp.log(lam + 1)))
    elif lam < 0:
        return -mp.sqrt(2*(lam - mp.log(lam + 1)))
    else:
        return 0 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:10,代碼來源:gammainc_asy.py

示例5: _student_t_cdf

# 需要導入模塊: import mpmath [as 別名]
# 或者: from mpmath import sqrt [as 別名]
def _student_t_cdf(df, t, dps=None):
    if dps is None:
        dps = mpmath.mp.dps
    with mpmath.workdps(dps):
        df, t = mpmath.mpf(df), mpmath.mpf(t)
        fac = mpmath.hyp2f1(0.5, 0.5*(df + 1), 1.5, -t**2/df)
        fac *= t*mpmath.gamma(0.5*(df + 1))
        fac /= mpmath.sqrt(mpmath.pi*df)*mpmath.gamma(0.5*df)
        return 0.5 + fac 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:11,代碼來源:test_cdflib.py

示例6: _noncentral_chi_pdf

# 需要導入模塊: import mpmath [as 別名]
# 或者: from mpmath import sqrt [as 別名]
def _noncentral_chi_pdf(t, df, nc):
    res = mpmath.besseli(df/2 - 1, mpmath.sqrt(nc*t))
    res *= mpmath.exp(-(t + nc)/2)*(t/nc)**(df/4 - 1/2)/2
    return res 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:6,代碼來源:test_cdflib.py

示例7: test_log_ndtr_complex

# 需要導入模塊: import mpmath [as 別名]
# 或者: from mpmath import sqrt [as 別名]
def test_log_ndtr_complex(self):
        assert_mpmath_equal(sc.log_ndtr,
                            exception_to_nan(lambda z: mpmath.log(mpmath.erfc(-z/np.sqrt(2.))/2.)),
                            [ComplexArg(a=complex(-10000, -100),
                                        b=complex(10000, 100))], n=200, dps=300) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:7,代碼來源:test_mpmath.py

示例8: test_j0

# 需要導入模塊: import mpmath [as 別名]
# 或者: from mpmath import sqrt [as 別名]
def test_j0(self):
        # The Bessel function at large arguments is j0(x) ~ cos(x + phi)/sqrt(x)
        # and at large arguments the phase of the cosine loses precision.
        #
        # This is numerically expected behavior, so we compare only up to
        # 1e8 = 1e15 * 1e-7
        assert_mpmath_equal(sc.j0,
                            mpmath.j0,
                            [Arg(-1e3, 1e3)])
        assert_mpmath_equal(sc.j0,
                            mpmath.j0,
                            [Arg(-1e8, 1e8)],
                            rtol=1e-5) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:15,代碼來源:test_mpmath.py

示例9: test_spherical_jn

# 需要導入模塊: import mpmath [as 別名]
# 或者: from mpmath import sqrt [as 別名]
def test_spherical_jn(self):
        def mp_spherical_jn(n, z):
            arg = mpmath.mpmathify(z)
            out = (mpmath.besselj(n + mpmath.mpf(1)/2, arg) /
                   mpmath.sqrt(2*arg/mpmath.pi))
            if arg.imag == 0:
                return out.real
            else:
                return out

        assert_mpmath_equal(lambda n, z: sc.spherical_jn(int(n), z),
                            exception_to_nan(mp_spherical_jn),
                            [IntArg(0, 200), Arg(-1e8, 1e8)],
                            dps=300) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:16,代碼來源:test_mpmath.py

示例10: test_spherical_jn_complex

# 需要導入模塊: import mpmath [as 別名]
# 或者: from mpmath import sqrt [as 別名]
def test_spherical_jn_complex(self):
        def mp_spherical_jn(n, z):
            arg = mpmath.mpmathify(z)
            out = (mpmath.besselj(n + mpmath.mpf(1)/2, arg) /
                   mpmath.sqrt(2*arg/mpmath.pi))
            if arg.imag == 0:
                return out.real
            else:
                return out

        assert_mpmath_equal(lambda n, z: sc.spherical_jn(int(n.real), z),
                            exception_to_nan(mp_spherical_jn),
                            [IntArg(0, 200), ComplexArg()]) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:15,代碼來源:test_mpmath.py

示例11: test_spherical_yn

# 需要導入模塊: import mpmath [as 別名]
# 或者: from mpmath import sqrt [as 別名]
def test_spherical_yn(self):
        def mp_spherical_yn(n, z):
            arg = mpmath.mpmathify(z)
            out = (mpmath.bessely(n + mpmath.mpf(1)/2, arg) /
                   mpmath.sqrt(2*arg/mpmath.pi))
            if arg.imag == 0:
                return out.real
            else:
                return out

        assert_mpmath_equal(lambda n, z: sc.spherical_yn(int(n), z),
                            exception_to_nan(mp_spherical_yn),
                            [IntArg(0, 200), Arg(-1e10, 1e10)],
                            dps=100) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:16,代碼來源:test_mpmath.py

示例12: test_spherical_in

# 需要導入模塊: import mpmath [as 別名]
# 或者: from mpmath import sqrt [as 別名]
def test_spherical_in(self):
        def mp_spherical_in(n, z):
            arg = mpmath.mpmathify(z)
            out = (mpmath.besseli(n + mpmath.mpf(1)/2, arg) /
                   mpmath.sqrt(2*arg/mpmath.pi))
            if arg.imag == 0:
                return out.real
            else:
                return out

        assert_mpmath_equal(lambda n, z: sc.spherical_in(int(n), z),
                            exception_to_nan(mp_spherical_in),
                            [IntArg(0, 200), Arg()],
                            dps=200, atol=10**(-278)) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:16,代碼來源:test_mpmath.py

示例13: test_spherical_in_complex

# 需要導入模塊: import mpmath [as 別名]
# 或者: from mpmath import sqrt [as 別名]
def test_spherical_in_complex(self):
        def mp_spherical_in(n, z):
            arg = mpmath.mpmathify(z)
            out = (mpmath.besseli(n + mpmath.mpf(1)/2, arg) /
                   mpmath.sqrt(2*arg/mpmath.pi))
            if arg.imag == 0:
                return out.real
            else:
                return out

        assert_mpmath_equal(lambda n, z: sc.spherical_in(int(n.real), z),
                            exception_to_nan(mp_spherical_in),
                            [IntArg(0, 200), ComplexArg()]) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:15,代碼來源:test_mpmath.py

示例14: test_spherical_kn

# 需要導入模塊: import mpmath [as 別名]
# 或者: from mpmath import sqrt [as 別名]
def test_spherical_kn(self):
        def mp_spherical_kn(n, z):
            out = (mpmath.besselk(n + mpmath.mpf(1)/2, z) *
                   mpmath.sqrt(mpmath.pi/(2*mpmath.mpmathify(z))))
            if mpmath.mpmathify(z).imag == 0:
                return out.real
            else:
                return out

        assert_mpmath_equal(lambda n, z: sc.spherical_kn(int(n), z),
                            exception_to_nan(mp_spherical_kn),
                            [IntArg(0, 150), Arg()],
                            dps=100) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:15,代碼來源:test_mpmath.py

示例15: test_spherical_kn_complex

# 需要導入模塊: import mpmath [as 別名]
# 或者: from mpmath import sqrt [as 別名]
def test_spherical_kn_complex(self):
        def mp_spherical_kn(n, z):
            arg = mpmath.mpmathify(z)
            out = (mpmath.besselk(n + mpmath.mpf(1)/2, arg) /
                   mpmath.sqrt(2*arg/mpmath.pi))
            if arg.imag == 0:
                return out.real
            else:
                return out

        assert_mpmath_equal(lambda n, z: sc.spherical_kn(int(n.real), z),
                            exception_to_nan(mp_spherical_kn),
                            [IntArg(0, 200), ComplexArg()],
                            dps=200) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:16,代碼來源:test_mpmath.py


注:本文中的mpmath.sqrt方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。