• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python gamma_functions.gamma函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sympy.functions.special.gamma_functions.gamma函数的典型用法代码示例。如果您正苦于以下问题:Python gamma函数的具体用法?Python gamma怎么用?Python gamma使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了gamma函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: taylor_term

 def taylor_term(n, x, *previous_terms):
     if n < 0:
         return S.Zero
     else:
         x = sympify(x)
         if len(previous_terms) > 1:
             p = previous_terms[-1]
             return (
                 (3 ** (S(1) / 3) * x) ** (-n)
                 * (3 ** (S(1) / 3) * x) ** (n + 1)
                 * sin(pi * (2 * n / 3 + S(4) / 3))
                 * factorial(n)
                 * gamma(n / 3 + S(2) / 3)
                 / (sin(pi * (2 * n / 3 + S(2) / 3)) * factorial(n + 1) * gamma(n / 3 + S(1) / 3))
                 * p
             )
         else:
             return (
                 S.One
                 / (3 ** (S(2) / 3) * pi)
                 * gamma((n + S.One) / S(3))
                 * sin(2 * pi * (n + S.One) / S(3))
                 / factorial(n)
                 * (root(3, 3) * x) ** n
             )
开发者ID:LuckyStrikes1090,项目名称:sympy,代码行数:25,代码来源:bessel.py


示例2: jacobi_normalized

def jacobi_normalized(n, a, b, x):
    r"""
    Jacobi polynomial :math:`P_n^{\left(\alpha, \beta\right)}(x)`

    jacobi_normalized(n, alpha, beta, x) gives the nth Jacobi polynomial
    in x, :math:`P_n^{\left(\alpha, \beta\right)}(x)`.

    The Jacobi polynomials are orthogonal on :math:`[-1, 1]` with respect
    to the weight :math:`\left(1-x\right)^\alpha \left(1+x\right)^\beta`.

    This functions returns the polynomials normilzed:

    .. math::

        \int_{-1}^{1}
          P_m^{\left(\alpha, \beta\right)}(x)
          P_n^{\left(\alpha, \beta\right)}(x)
          (1-x)^{\alpha} (1+x)^{\beta} \mathrm{d}x
        = \delta_{m,n}

    Examples
    ========

    >>> from sympy import jacobi_normalized
    >>> from sympy.abc import n,a,b,x

    >>> jacobi_normalized(n, a, b, x)
    jacobi(n, a, b, x)/sqrt(2**(a + b + 1)*gamma(a + n + 1)*gamma(b + n + 1)/((a + b + 2*n + 1)*factorial(n)*gamma(a + b + n + 1)))

    See Also
    ========

    gegenbauer,
    chebyshevt_root, chebyshevu, chebyshevu_root,
    legendre, assoc_legendre,
    hermite,
    laguerre, assoc_laguerre,
    sympy.polys.orthopolys.jacobi_poly,
    sympy.polys.orthopolys.gegenbauer_poly
    sympy.polys.orthopolys.chebyshevt_poly
    sympy.polys.orthopolys.chebyshevu_poly
    sympy.polys.orthopolys.hermite_poly
    sympy.polys.orthopolys.legendre_poly
    sympy.polys.orthopolys.laguerre_poly

    References
    ==========

    .. [1] http://en.wikipedia.org/wiki/Jacobi_polynomials
    .. [2] http://mathworld.wolfram.com/JacobiPolynomial.html
    .. [3] http://functions.wolfram.com/Polynomials/JacobiP/
    """
    nfactor = (
        S(2) ** (a + b + 1)
        * (gamma(n + a + 1) * gamma(n + b + 1))
        / (2 * n + a + b + 1)
        / (factorial(n) * gamma(n + a + b + 1))
    )

    return jacobi(n, a, b, x) / sqrt(nfactor)
开发者ID:B-Rich,项目名称:sympy,代码行数:60,代码来源:polynomials.py


示例3: _eval_rewrite_as_polynomial

 def _eval_rewrite_as_polynomial(self, n, x):
     from sympy import Sum
     # TODO: Should make sure n is in N_0
     k = Dummy("k")
     kern = RisingFactorial(
         -n, k) / (gamma(k + alpha + 1) * factorial(k)) * x**k
     return gamma(n + alpha + 1) / factorial(n) * Sum(kern, (k, 0, n))
开发者ID:amitsaha,项目名称:sympy,代码行数:7,代码来源:polynomials.py


示例4: _eval_rewrite_as_polynomial

 def _eval_rewrite_as_polynomial(self, n, x):
     from sympy import Sum
     # Make sure n \in N_0
     if n.is_negative or n.is_integer is False:
         raise ValueError("Error: n should be a non-negative integer.")
     k = Dummy("k")
     kern = RisingFactorial(
         -n, k) / (gamma(k + alpha + 1) * factorial(k)) * x**k
     return gamma(n + alpha + 1) / factorial(n) * Sum(kern, (k, 0, n))
开发者ID:ChaliZhg,项目名称:sympy,代码行数:9,代码来源:polynomials.py


示例5: pdf

 def pdf(self, *args):
     from sympy.functions.special.gamma_functions import gamma
     mu, sigma = self.mu, self.shape_mat
     v = S(self.dof)
     k = S(len(mu))
     sigma_inv = sigma.inv()
     args = ImmutableMatrix(args)
     x = args - mu
     return gamma((k + v)/2)/(gamma(v/2)*(v*pi)**(k/2)*sqrt(det(sigma)))\
     *(1 + 1/v*(x.transpose()*sigma_inv*x)[0])**((-v - k)/2)
开发者ID:asmeurer,项目名称:sympy,代码行数:10,代码来源:joint_rv_types.py


示例6: eval

 def eval(cls, z):
     if z is S.Zero:
         return pi / 2
     elif z is S.Half:
         return 8 * pi ** (S(3) / 2) / gamma(-S(1) / 4) ** 2
     elif z is S.One:
         return S.ComplexInfinity
     elif z is S.NegativeOne:
         return gamma(S(1) / 4) ** 2 / (4 * sqrt(2 * pi))
     elif z in (S.Infinity, S.NegativeInfinity, I * S.Infinity, I * S.NegativeInfinity, S.ComplexInfinity):
         return S.Zero
开发者ID:guanlongtianzi,项目名称:sympy,代码行数:11,代码来源:elliptic_integrals.py


示例7: marginal_distribution

 def marginal_distribution(self, indices, *sym):
     from sympy.functions.special.gamma_functions import gamma
     if len(indices) == 2:
         return self.pdf(*sym)
     if indices[0] == 0:
         #For marginal over `x`, return non-standardized Student-T's
         #distribution
         x = sym[0]
         v, mu, sigma = self.alpha - S(1)/2, self.mu, \
             S(self.beta)/(self.lamda * self.alpha)
         return Lambda(sym, gamma((v + 1)/2)/(gamma(v/2)*sqrt(pi*v)*sigma)*\
             (1 + 1/v*((x - mu)/sigma)**2)**((-v -1)/2))
     #For marginal over `tau`, return Gamma distribution as per construction
     from sympy.stats.crv_types import GammaDistribution
     return Lambda(sym, GammaDistribution(self.alpha, self.beta)(sym[0]))
开发者ID:asmeurer,项目名称:sympy,代码行数:15,代码来源:joint_rv_types.py


示例8: eval

 def eval(cls, n, m, x):
     if m.could_extract_minus_sign():
         # P^{-m}_n  --->  F * P^m_n
         return S.NegativeOne**(-m) * (factorial(m + n)/factorial(n - m)) * assoc_legendre(n, -m, x)
     if m == 0:
         # P^0_n  --->  L_n
         return legendre(n, x)
     if x == 0:
         return 2**m*sqrt(S.Pi) / (gamma((1 - m - n)/2)*gamma(1 - (m - n)/2))
     if n.is_Number and m.is_Number and n.is_integer and m.is_integer:
         if n.is_negative:
             raise ValueError("%s : 1st index must be nonnegative integer (got %r)" % (cls, n))
         if abs(m) > n:
             raise ValueError("%s : abs('2nd index') must be <= '1st index' (got %r, %r)" % (cls, n, m))
         return cls._eval_at_order(int(n), abs(int(m))).subs(_x, x)
开发者ID:ChaliZhg,项目名称:sympy,代码行数:15,代码来源:polynomials.py


示例9: eval

 def eval(cls, arg):
     if arg.is_Number:
         if arg is S.NaN:
             return S.NaN
         elif arg is S.Infinity:
             return S.Zero
         elif arg is S.Zero:
             return -S.One / (3 ** Rational(1, 3) * gamma(Rational(1, 3)))
开发者ID:LuckyStrikes1090,项目名称:sympy,代码行数:8,代码来源:bessel.py


示例10: taylor_term

 def taylor_term(n, x, *previous_terms):
     if n < 0:
         return S.Zero
     else:
         x = sympify(x)
         if len(previous_terms) > 1:
             p = previous_terms[-1]
             return (3**(S(1)/3)*x * Abs(sin(2*pi*(n + S.One)/S(3))) * C.factorial((n - S.One)/S(3)) /
                     ((n + S.One) * Abs(cos(2*pi*(n + S.Half)/S(3))) * C.factorial((n - 2)/S(3))) * p)
         else:
             return (S.One/(root(3, 6)*pi) * gamma((n + S.One)/S(3)) * Abs(sin(2*pi*(n + S.One)/S(3))) /
                     C.factorial(n) * (root(3, 3)*x)**n)
开发者ID:AdrianPotter,项目名称:sympy,代码行数:12,代码来源:bessel.py


示例11: eval

 def eval(cls, n, x):
     if not n.is_Number:
         # Symbolic result L_n(x)
         # L_n(-x)  --->  (-1)**n * L_n(x)
         if x.could_extract_minus_sign():
             return S.NegativeOne**n * legendre(n, -x)
         # L_{-n}(x)  --->  L_{n-1}(x)
         if n.could_extract_minus_sign():
             return legendre(-n - S.One, x)
         # We can evaluate for some special values of x
         if x == S.Zero:
             return sqrt(S.Pi)/(gamma(S.Half - n/2)*gamma(S.One + n/2))
         elif x == S.One:
             return S.One
         elif x == S.Infinity:
             return S.Infinity
     else:
         # n is a given fixed integer, evaluate into polynomial;
         # L_{-n}(x)  --->  L_{n-1}(x)
         if n.is_negative:
             n = -n - S.One
         return cls._eval_at_order(n, x)
开发者ID:cmarqu,项目名称:sympy,代码行数:22,代码来源:polynomials.py


示例12: eval

    def eval(cls, n, a, b, x):
        # Simplify to other polynomials
        # P^{a, a}_n(x)
        if a == b:
            if a == -S.Half:
                return RisingFactorial(S.Half, n) / factorial(n) * chebyshevt(n, x)
            elif a == S.Zero:
                return legendre(n, x)
            elif a == S.Half:
                return RisingFactorial(3*S.Half, n) / factorial(n + 1) * chebyshevu(n, x)
            else:
                return RisingFactorial(a + 1, n) / RisingFactorial(2*a + 1, n) * gegenbauer(n, a + S.Half, x)
        elif b == -a:
            # P^{a, -a}_n(x)
            return gamma(n + a + 1) / gamma(n + 1) * (1 + x)**(a/2) / (1 - x)**(a/2) * assoc_legendre(n, -a, x)


        if not n.is_Number:
            # Symbolic result P^{a,b}_n(x)
            # P^{a,b}_n(-x)  --->  (-1)**n * P^{b,a}_n(-x)
            if x.could_extract_minus_sign():
                return S.NegativeOne**n * jacobi(n, b, a, -x)
            # We can evaluate for some special values of x
            if x == S.Zero:
                return (2**(-n) * gamma(a + n + 1) / (gamma(a + 1) * factorial(n)) *
                        hyper([-b - n, -n], [a + 1], -1))
            if x == S.One:
                return RisingFactorial(a + 1, n) / factorial(n)
            elif x == S.Infinity:
                if n.is_positive:
                    # Make sure a+b+2*n \notin Z
                    if (a + b + 2*n).is_integer:
                        raise ValueError("Error. a + b + 2*n should not be an integer.")
                    return RisingFactorial(a + b + n + 1, n) * S.Infinity
        else:
            # n is a given fixed integer, evaluate into polynomial
            return jacobi_poly(n, a, b, x)
开发者ID:fanminshi,项目名称:sympy,代码行数:37,代码来源:polynomials.py


示例13: gauss_gen_laguerre

def gauss_gen_laguerre(n, alpha, n_digits):
    r"""
    Computes the generalized Gauss-Laguerre quadrature [1]_ points and weights.

    The generalized Gauss-Laguerre quadrature approximates the integral:

    .. math::
        \int_{0}^\infty x^{\alpha} e^{-x} f(x)\,dx \approx \sum_{i=1}^n w_i f(x_i)

    The nodes `x_i` of an order `n` quadrature rule are the roots of `L^{\alpha}_n`
    and the weights `w_i` are given by:

    .. math::
        w_i = \frac{\Gamma(\alpha+n)}{n \Gamma(n) L^{\alpha}_{n-1}(x_i) L^{\alpha+1}_{n-1}(x_i)}

    Parameters
    ==========

    n : the order of quadrature

    alpha : the exponent of the singularity, `\alpha > -1`

    n_digits : number of significant digits of the points and weights to return

    Returns
    =======

    (x, w) : the ``x`` and ``w`` are lists of points and weights as Floats.
             The points `x_i` and weights `w_i` are returned as ``(x, w)``
             tuple of lists.

    Examples
    ========

    >>> from sympy import S
    >>> from sympy.integrals.quadrature import gauss_gen_laguerre
    >>> x, w = gauss_gen_laguerre(3, -S.Half, 5)
    >>> x
    [0.19016, 1.7845, 5.5253]
    >>> w
    [1.4493, 0.31413, 0.00906]

    >>> x, w = gauss_gen_laguerre(4, 3*S.Half, 5)
    >>> x
    [0.97851, 2.9904, 6.3193, 11.712]
    >>> w
    [0.53087, 0.67721, 0.11895, 0.0023152]

    See Also
    ========

    gauss_legendre, gauss_laguerre, gauss_hermite, gauss_chebyshev_t, gauss_chebyshev_u, gauss_jacobi

    References
    ==========

    .. [1] http://en.wikipedia.org/wiki/Gauss%E2%80%93Laguerre_quadrature
    .. [2] http://people.sc.fsu.edu/~jburkardt/cpp_src/gen_laguerre_rule/gen_laguerre_rule.html
    """
    x = Dummy("x")
    p = laguerre_poly(n, x, alpha=alpha, polys=True)
    p1 = laguerre_poly(n-1, x, alpha=alpha, polys=True)
    p2 = laguerre_poly(n-1, x, alpha=alpha+1, polys=True)
    xi = []
    w  = []
    for r in p.real_roots():
        if isinstance(r, RootOf):
            r = r.eval_rational(S(1)/10**(n_digits+2))
        xi.append(r.n(n_digits))
        w.append((gamma(alpha+n)/(n*gamma(n)*p1.subs(x, r)*p2.subs(x, r))).n(n_digits))
    return xi, w
开发者ID:AALEKH,项目名称:sympy,代码行数:71,代码来源:quadrature.py


示例14: gauss_jacobi

def gauss_jacobi(n, alpha, beta, n_digits):
    r"""
    Computes the Gauss-Jacobi quadrature [1]_ points and weights.

    The Gauss-Jacobi quadrature of the first kind approximates the integral:

    .. math::
        \int_{-1}^1 (1-x)^\alpha (1+x)^\beta f(x)\,dx \approx \sum_{i=1}^n w_i f(x_i)

    The nodes `x_i` of an order `n` quadrature rule are the roots of `P^{(\alpha,\beta)}_n`
    and the weights `w_i` are given by:

    .. math::
        w_i = -\frac{2n+\alpha+\beta+2}{n+\alpha+\beta+1}\frac{\Gamma(n+\alpha+1)\Gamma(n+\beta+1)}
              {\Gamma(n+\alpha+\beta+1)(n+1)!} \frac{2^{\alpha+\beta}}{P'_n(x_i)
              P^{(\alpha,\beta)}_{n+1}(x_i)}

    Parameters
    ==========

    n : the order of quadrature

    alpha : the first parameter of the Jacobi Polynomial, `\alpha > -1`

    beta : the second parameter of the Jacobi Polynomial, `\beta > -1`

    n_digits : number of significant digits of the points and weights to return

    Returns
    =======

    (x, w) : the ``x`` and ``w`` are lists of points and weights as Floats.
             The points `x_i` and weights `w_i` are returned as ``(x, w)``
             tuple of lists.

    Examples
    ========

    >>> from sympy import S
    >>> from sympy.integrals.quadrature import gauss_jacobi
    >>> x, w = gauss_jacobi(3, S.Half, -S.Half, 5)
    >>> x
    [-0.90097, -0.22252, 0.62349]
    >>> w
    [1.7063, 1.0973, 0.33795]

    >>> x, w = gauss_jacobi(6, 1, 1, 5)
    >>> x
    [-0.87174, -0.5917, -0.2093, 0.2093, 0.5917, 0.87174]
    >>> w
    [0.050584, 0.22169, 0.39439, 0.39439, 0.22169, 0.050584]

    See Also
    ========

    gauss_legendre, gauss_laguerre, gauss_hermite, gauss_gen_laguerre, gauss_chebyshev_t, gauss_chebyshev_u

    References
    ==========

    .. [1] http://en.wikipedia.org/wiki/Gauss%E2%80%93Jacobi_quadrature
    .. [2] http://people.sc.fsu.edu/~jburkardt/cpp_src/jacobi_rule/jacobi_rule.html
    .. [3] http://people.sc.fsu.edu/~jburkardt/cpp_src/gegenbauer_rule/gegenbauer_rule.html
    """
    x = Dummy("x")
    p = jacobi_poly(n, alpha, beta, x, polys=True)
    pd = p.diff(x)
    pn = jacobi_poly(n+1, alpha, beta, x, polys=True)
    xi = []
    w  = []
    for r in p.real_roots():
        if isinstance(r, RootOf):
            r = r.eval_rational(S(1)/10**(n_digits+2))
        xi.append(r.n(n_digits))
        w.append((
            - (2*n+alpha+beta+2) / (n+alpha+beta+S.One)
            * (gamma(n+alpha+1)*gamma(n+beta+1)) / (gamma(n+alpha+beta+S.One)*gamma(n+2))
            * 2**(alpha+beta) / (pd.subs(x, r) * pn.subs(x, r))
        ).n(n_digits))
    return xi, w
开发者ID:AALEKH,项目名称:sympy,代码行数:80,代码来源:quadrature.py


示例15: _eval_rewrite_as_hyper

 def _eval_rewrite_as_hyper(self, z):
     pf1 = z ** 2 / (2 * root(3, 6) * gamma(S(2) / 3))
     pf2 = root(3, 6) / gamma(S(1) / 3)
     return pf1 * hyper([], [S(5) / 3], z ** 3 / 9) + pf2 * hyper([], [S(1) / 3], z ** 3 / 9)
开发者ID:LuckyStrikes1090,项目名称:sympy,代码行数:4,代码来源:bessel.py


示例16: test_sympy__functions__special__gamma_functions__gamma

def test_sympy__functions__special__gamma_functions__gamma():
    from sympy.functions.special.gamma_functions import gamma
    assert _test_args(gamma(x))
开发者ID:101man,项目名称:sympy,代码行数:3,代码来源:test_args.py


示例17: _eval_expand_func

 def _eval_expand_func(self, **hints):
     x, y = self.args
     return gamma(x)*gamma(y) / gamma(x + y)
开发者ID:A-turing-machine,项目名称:sympy,代码行数:3,代码来源:beta_functions.py



注:本文中的sympy.functions.special.gamma_functions.gamma函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python hyper.hyper函数代码示例发布时间:2022-05-27
下一篇:
Python bessel.yn函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap