本文整理汇总了Python中sympy.Poly.coeff方法的典型用法代码示例。如果您正苦于以下问题:Python Poly.coeff方法的具体用法?Python Poly.coeff怎么用?Python Poly.coeff使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.Poly
的用法示例。
在下文中一共展示了Poly.coeff方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_coeff
# 需要导入模块: from sympy import Poly [as 别名]
# 或者: from sympy.Poly import coeff [as 别名]
def test_coeff():
p = Poly(3*x**2*y + 4*x*y**2 + 1, x, y)
assert p.coeff(0, 0) == p.coeff() == 1
assert p.coeff(2, 1) == 3
assert p.coeff(1, 2) == 4
assert p.coeff(1, 1) == 0
示例2: poly_factorize
# 需要导入模块: from sympy import Poly [as 别名]
# 或者: from sympy.Poly import coeff [as 别名]
def poly_factorize(poly):
"""Factorize multivariate polynomials into a sum of products of monomials.
This function can be used to decompose polynomials into a form which
minimizes the number of additions and multiplications, and which thus
can be evaluated efficently."""
max_deg = {}
if 'horner' in dir(sympy):
return sympy.horner(poly)
if not isinstance(poly, Poly):
poly = Poly(sympy.expand(poly), *poly.atoms(Symbol))
denom, poly = poly.as_integer()
# Determine the order of factorization. We proceed through the
# symbols, starting with the one present in the highest order
# in the polynomial.
for i, sym in enumerate(poly.symbols):
max_deg[i] = 0
for monom in poly.monoms:
for i, symvar in enumerate(monom):
max_deg[i] = max(max_deg[i], symvar)
ret_poly = 0
monoms = list(poly.monoms)
for isym, maxdeg in sorted(max_deg.items(), key=itemgetter(1), reverse=True):
drop_idx = []
new_poly = []
for i, monom in enumerate(monoms):
if monom[isym] > 0:
drop_idx.append(i)
new_poly.append((poly.coeff(*monom), monom))
if not new_poly:
continue
ret_poly += sympy.factor(Poly(new_poly, *poly.symbols))
for idx in reversed(drop_idx):
del monoms[idx]
# Add any remaining O(1) terms.
new_poly = []
for i, monom in enumerate(monoms):
new_poly.append((poly.coeff(*monom), monom))
if new_poly:
ret_poly += Poly(new_poly, *poly.symbols)
return ret_poly / denom
示例3: main
# 需要导入模块: from sympy import Poly [as 别名]
# 或者: from sympy.Poly import coeff [as 别名]
def main():
x=Symbol("x")
s = Poly(A(x), x)
num = [s.coeff(n) for n in range(11)]
print s.as_basic()
print num