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


Python Poly.as_basic方法代码示例

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


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

示例1: main

# 需要导入模块: from sympy import Poly [as 别名]
# 或者: from sympy.Poly import as_basic [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
开发者ID:KevinGoodsell,项目名称:sympy,代码行数:9,代码来源:trees.py

示例2: main

# 需要导入模块: from sympy import Poly [as 别名]
# 或者: from sympy.Poly import as_basic [as 别名]
def main():
    x=Symbol("x")
    s = Poly(A(x), x)
    num = list(reversed(s.coeffs()))[:11]

    print s.as_basic()
    print num
开发者ID:Aang,项目名称:sympy,代码行数:9,代码来源:trees.py

示例3: new_poly

# 需要导入模块: from sympy import Poly [as 别名]
# 或者: from sympy.Poly import as_basic [as 别名]
def new_poly(V_s, fields, n_coeffs):
    """Make a new polynomial function that has the same powers as V_s function
       but with coefficients C1, C2..."""
    
    from sympy import Poly
    from sympy import diff, Symbol, var, simplify, sympify, S
    from sympy.core.sympify import SympifyError
    
    P = Poly(V_s,*fields)
    d = P.as_dict()
    e = {}
    
    for key in d.iterkeys():
        #print d[key], str(d[key])
        for i in xrange(1, n_coeffs+1):
            if 'C' + str(i) in str(d[key]):
                e[key] = sympify('C'+str(i))

    P2 = Poly(e,*fields)
    return str(P2.as_basic())
开发者ID:jtksai,项目名称:PyCOOL,代码行数:22,代码来源:misc_functions.py

示例4: test_poly_div

# 需要导入模块: from sympy import Poly [as 别名]
# 或者: from sympy.Poly import as_basic [as 别名]
def test_poly_div():
    f = Poly(x**3-12*x**2-42, x)
    g = Poly(x**2+x-3, x)

    h = poly_div(f, g)

    assert h[0] == Poly(x-13, x)
    assert h[1] == Poly(16*x-81, x)

    assert h[0].as_basic() == x-13
    assert h[1].as_basic() == 16*x-81

    assert f / g == Poly(x-13, x)
    assert f % g == Poly(16*x-81, x)

    assert divmod(f, g) == (Poly(x-13, x), Poly(16*x-81, x))

    assert f / x == Poly(x**2-12*x, x)
    assert f % x == Poly(-42, x)

    assert divmod(f, x) == (Poly(x**2-12*x, x), Poly(-42, x))

    assert f / sin(x) == f.as_basic() / sin(x)
    assert f % sin(x) == 0

    assert divmod(f, sin(x)) == (f.as_basic() / sin(x), 0)

    assert poly_div(4*x**2*y-2*x*y-2*y+4*x+8, 2, x, y) == \
        (Poly(2*x**2*y-x*y-y+2*x+4, x, y), Poly((), x, y))

    assert poly_div(4*x**2*y-2*x*y-2*y+4*x+8, 2*y, x, y) == \
        (Poly(2*x**2-x-1, x, y), Poly(4*x+8, x, y))

    assert poly_div(x-1, y-1, x, y) == (Poly((), x, y), Poly(x-1, x, y))

    assert poly_div(x**3-12*x**2-42, x-3, x) == \
        (Poly(x**2-9*x-27, x), Poly(-123, x))

    assert poly_div(2+2*x+x**2, 1, x) == (Poly(2+2*x+x**2, x), Poly(0, x))
    assert poly_div(2+2*x+x**2, 2, x) == (Poly(1+x+x**2/2, x), Poly(0, x))

    assert poly_div(3*x**3, x**2, x) == (Poly(3*x, x), Poly(0, x))

    assert poly_div(1, x, x) == (Poly(0, x), Poly(1, x))

    assert poly_div(x*y+2*x+y,x,x) == (Poly(2+y, x), Poly(y, x))

    assert poly_div(x*y**2 + 1, [x*y+1, y+1], x, y) == \
        ([Poly(y, x, y), Poly(-1, x, y)], Poly(2, x, y))

    assert poly_div(x**2*y+x*y**2+y**2, [x*y-1, y**2-1], x, y) == \
        ([Poly(x+y, x, y), Poly(1, x, y)], Poly(1+x+y, x, y))
    assert poly_div(x**2*y+x*y**2+y**2, [y**2-1, x*y-1], x, y) == \
        ([Poly(1+x, x, y), Poly(x, x, y)], Poly(1+2*x, x, y))

    f, g = 3*x**3 + x**2 + x + 5, 5*x**2 - 3*x + 1

    q = Poly(Rational(3,5)*x + Rational(14, 25), x)
    r = Poly(Rational(52, 25)*x + Rational(111, 25), x)

    assert poly_div(f, g, x) == (q, r)
    assert poly_div(Poly(f, x), Poly(g, x)) == (q, r)

    q = Poly(15*x + 14, x)
    r = Poly(52*x + 111, x)

    assert poly_pdiv(f, g, x) == (q, r)
    assert poly_pdiv(Poly(f, x), Poly(g, x)) == (q, r)
开发者ID:jcockayne,项目名称:sympy-rkern,代码行数:70,代码来源:test_polynomial.py


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