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


Python Poly.diff方法代码示例

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


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

示例1: test_squarefree

# 需要导入模块: from sympy import Poly [as 别名]
# 或者: from sympy.Poly import diff [as 别名]
def test_squarefree():
    assert Poly(x-1, x).is_squarefree == True
    assert Poly((x-1)**2, x).is_squarefree == False

    assert Poly(3*x**2, x).as_squarefree() == Poly(3*x, x)
    assert Poly(x**2+2*x+1, x).as_squarefree() == Poly(x+1, x)
    assert Poly(x**5-x**4-x+1, x).as_squarefree() == Poly(x**4-1, x)

    assert poly_sqf(1, x) == [Poly(1, x)]
    assert poly_sqf(x, x) == [Poly(x, x)]

    assert poly_sqf(3*x**2, x) == [Poly(3, x), Poly(x, x)]
    assert poly_sqf(x**2+2*x+1, x) == [Poly(1, x), Poly(x+1, x)]

    assert poly_sqf(x**5-x**4-x+1, x) == \
        [Poly(x**3 + x**2 + x + 1, x), Poly(x-1, x)]
    assert poly_sqf(x**8+6*x**6+12*x**4+8*x**2, x) == \
        [Poly(1, x), Poly(x, x), Poly(x**2+2, x)]

    # Bronstein, Symbolic Integration, pp. 52

    A = Poly(x**4 - 3*x**2 + 6, x)
    D = Poly(x**6 - 5*x**4 + 5*x**2 + 4, x)

    f, g = D, A - D.diff(x).mul_term(t)

    res, R = poly_subresultants(f, g)
    S = poly_sqf(Poly(res, t))

    assert S == [Poly(45796, t), Poly(1, t), Poly(4*t**2 + 1, t)]
开发者ID:fperez,项目名称:sympy,代码行数:32,代码来源:test_polynomial.py

示例2: test_diff

# 需要导入模块: from sympy import Poly [as 别名]
# 或者: from sympy.Poly import diff [as 别名]
def test_diff():
    f = Poly(a*x**2 + b*x + 2, x)

    assert f.diff(x) == Poly(2*a*x + b, x)
    assert f.diff(y) == Poly(0, x)
    assert f.diff(a) == Poly(x**2, x)
    assert f.diff(b) == Poly(x, x)

    assert f.diff() == Poly(2*a*x + b, x)

    g = Poly(a*x**2 + b*x*y + 2, x, y)

    assert g.diff(x) == Poly(2*a*x + b*y, x, y)
    assert g.diff(y) == Poly(b*x, x, y)
    assert g.diff(a) == Poly(x**2, x, y)
    assert g.diff(b) == Poly(x*y, x, y)

    assert g.diff() == g
开发者ID:jcockayne,项目名称:sympy-rkern,代码行数:20,代码来源:test_polynomial.py

示例3: ratint_ratpart

# 需要导入模块: from sympy import Poly [as 别名]
# 或者: from sympy.Poly import diff [as 别名]
def ratint_ratpart(f, g, x):
    """Horowitz-Ostrogradsky algorithm.

       Given a field K and polynomials f and g in K[x], such that f and g
       are coprime and deg(f) < deg(g), returns fractions A and B in K(x),
       such that f/g = A' + B and B has square-free denominator.

    """
    f, g = Poly(f, x), Poly(g, x)

    u = poly_gcd(g, g.diff())
    v = poly_div(g, u)[0]

    n = u.degree - 1
    m = v.degree - 1
    d = g.degree

    A_coeff = [ Symbol('a' + str(n-i), dummy=True) for i in xrange(0, n+1) ]
    B_coeff = [ Symbol('b' + str(m-i), dummy=True) for i in xrange(0, m+1) ]

    symbols = A_coeff + B_coeff

    A = Poly(zip(A_coeff, xrange(n, -1, -1)), x)
    B = Poly(zip(B_coeff, xrange(m, -1, -1)), x)

    H = f - A.diff()*v + A*poly_div(u.diff()*v, u)[0] - B*u

    result = solve(H.coeffs, symbols)

    A = A.subs(result)
    B = B.subs(result)

    rat_part = Poly.cancel((A, u), x)
    log_part = Poly.cancel((B, v), x)

    return rat_part, log_part
开发者ID:Praveen-Ramanujam,项目名称:MobRAVE,代码行数:38,代码来源:rationaltools.py

示例4: evtupoly

# 需要导入模块: from sympy import Poly [as 别名]
# 或者: from sympy.Poly import diff [as 别名]
def evtupoly(n,d):
    """
    Generates a random polynomial in n
    variables with largest degree d.
    """
    from scipy.misc import comb
    from sympy import var, Poly, Matrix
    from numpy import zeros, empty

    m = comb(d-1+n,n,exact=1)
    print 'number of terms: ', m, '+', n, 'leading terms'
    print ''
    (C,E) = randpoly(n,d-1)
    for i in range(0,n):
        C.append(10)
        t = [0 for j in range(0,n)]
        t[i] = d
        E.append(tuple(t))
    print 'coefficients:'
    print C
    print ''
    print 'exponents:'
    print E
    print ''

    # Set up variables
    S = ['x' + str(i) for i in range(1,n+1)]

    # Construct symbolic polynomial
    p = Poly(strpoly(S,C,E),var(S))
    print 'sympy expression:'
    print p
    print ''

    # Construct polynomial function
    def pf(x):
        return float(p.eval(zip(S,x)))

    # Calculate symbolic gradient
    grad = Matrix(n,1, lambda i,j: p.diff(S[i]))
    print 'sympy gradient:'
    print grad
    print ''

    # Construct gradient function
    def pg(x):
        gval = zeros(n)
        for i in range(0,n):
            gval[i] = float(grad[i].eval(zip(S,x)))
        return gval

    # Calculate symbolic Hessian
    H = Matrix(n,n, lambda i,j: (p.diff(S[i])).diff(S[j]))
    print 'sympy Hessian:'
    print H
    print ''

    # Construct Hessian function
    def pH(x):
        Hval = zeros((n,n))
        for i in range(0,n):
            for j in range(0,n):
                Hval[i,j] = float(H[i,j].eval(zip(S,x)))
        return Hval

    # Calculate symbolic derivative Tensor
    T = empty((n,n,n),dtype='object')
    for i in range(0,n):
        for j in range(0,n):
            for k in range(0,n):
                T[i,j,k] = ((p.diff(S[i])).diff(S[j])).diff(S[k])

    print 'sympy Tensor:'
    print T
    print ''

    # Construct Hessian bounding function
    def bndH(l,u):
        """
        Bound Hessian over l_i <= x_i <= u_i
        """
        LH = zeros((n,n))
        UH = zeros((n,n))

        # Lower bound
        # See which entries have even exponent
        for i in range(0,n):
            for j in range(0,n):

            # Get exponents and coefficients
                E = H[i,j].monoms()
                C = H[i,j].coeffs()

                # For each term
                for t in range(0,len(E)):

                # Containers
                    L = 1
                    U = 1

#.........这里部分代码省略.........
开发者ID:Alberto0991,项目名称:oBB,代码行数:103,代码来源:evtupoly.py


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