当前位置: 首页>>代码示例>>Python>>正文


Python Poly.all_coeffs方法代码示例

本文整理汇总了Python中sympy.polys.polytools.Poly.all_coeffs方法的典型用法代码示例。如果您正苦于以下问题:Python Poly.all_coeffs方法的具体用法?Python Poly.all_coeffs怎么用?Python Poly.all_coeffs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sympy.polys.polytools.Poly的用法示例。


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

示例1: _eval_sum_hyper

# 需要导入模块: from sympy.polys.polytools import Poly [as 别名]
# 或者: from sympy.polys.polytools.Poly import all_coeffs [as 别名]
def _eval_sum_hyper(f, i, a):
    """ Returns (res, cond). Sums from a to oo. """
    from sympy.functions import hyper
    from sympy.simplify import hyperexpand, hypersimp, fraction, simplify
    from sympy.polys.polytools import Poly, factor
    from sympy.core.numbers import Float

    if a != 0:
        return _eval_sum_hyper(f.subs(i, i + a), i, 0)

    if f.subs(i, 0) == 0:
        if simplify(f.subs(i, Dummy('i', integer=True, positive=True))) == 0:
            return S(0), True
        return _eval_sum_hyper(f.subs(i, i + 1), i, 0)

    hs = hypersimp(f, i)
    if hs is None:
        return None

    if isinstance(hs, Float):
        from sympy.simplify.simplify import nsimplify
        hs = nsimplify(hs)

    numer, denom = fraction(factor(hs))
    top, topl = numer.as_coeff_mul(i)
    bot, botl = denom.as_coeff_mul(i)
    ab = [top, bot]
    factors = [topl, botl]
    params = [[], []]
    for k in range(2):
        for fac in factors[k]:
            mul = 1
            if fac.is_Pow:
                mul = fac.exp
                fac = fac.base
                if not mul.is_Integer:
                    return None
            p = Poly(fac, i)
            if p.degree() != 1:
                return None
            m, n = p.all_coeffs()
            ab[k] *= m**mul
            params[k] += [n/m]*mul

    # Add "1" to numerator parameters, to account for implicit n! in
    # hypergeometric series.
    ap = params[0] + [1]
    bq = params[1]
    x = ab[0]/ab[1]
    h = hyper(ap, bq, x)

    return f.subs(i, 0)*hyperexpand(h), h.convergence_statement
开发者ID:carstimon,项目名称:sympy,代码行数:54,代码来源:summations.py

示例2: horner

# 需要导入模块: from sympy.polys.polytools import Poly [as 别名]
# 或者: from sympy.polys.polytools.Poly import all_coeffs [as 别名]
def horner(f, *gens, **args):
    """
    Rewrite a polynomial in Horner form.

    Among other applications, evaluation of a polynomial at a point is optimal
    when it is applied using the Horner scheme ([1]).

    Examples
    ========

    >>> from sympy.polys.polyfuncs import horner
    >>> from sympy.abc import x, y, a, b, c, d, e

    >>> horner(9*x**4 + 8*x**3 + 7*x**2 + 6*x + 5)
    x*(x*(x*(9*x + 8) + 7) + 6) + 5

    >>> horner(a*x**4 + b*x**3 + c*x**2 + d*x + e)
    e + x*(d + x*(c + x*(a*x + b)))

    >>> f = 4*x**2*y**2 + 2*x**2*y + 2*x*y**2 + x*y

    >>> horner(f, wrt=x)
    x*(x*y*(4*y + 2) + y*(2*y + 1))

    >>> horner(f, wrt=y)
    y*(x*y*(4*x + 2) + x*(2*x + 1))

    References
    ==========
    [1] - http://en.wikipedia.org/wiki/Horner_scheme

    """
    allowed_flags(args, [])

    try:
        F, opt = poly_from_expr(f, *gens, **args)
    except PolificationFailed as exc:
        return exc.expr

    form, gen = S.Zero, F.gen

    if F.is_univariate:
        for coeff in F.all_coeffs():
            form = form*gen + coeff
    else:
        F, gens = Poly(F, gen), gens[1:]

        for coeff in F.all_coeffs():
            form = form*gen + horner(coeff, *gens, **args)

    return form
开发者ID:AALEKH,项目名称:sympy,代码行数:53,代码来源:polyfuncs.py

示例3: full_coeffs

# 需要导入模块: from sympy.polys.polytools import Poly [as 别名]
# 或者: from sympy.polys.polytools.Poly import all_coeffs [as 别名]
def full_coeffs(p,D,s):
    '''
    Computes coefficients of a polynomial matrix
    p : polynomial
    D :degree  up to which we want to complete the list 	with zeroes
    s: variable of the polynomial matrix
    Example:  TODO
    '''
    p=Poly(p,s,domain='QQ')  # in order to use the all_coeffs method of polynomial class
    c=p.all_coeffs()
    if len(c)==D+1:
        return c
    else:
        difference=D+1-len(c)
        return difference*[0] +c
开发者ID:ChristosT,项目名称:polynomial2gss,代码行数:17,代码来源:matrix_coefficients.py


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