本文整理汇总了Python中sympy.polys.Poly.count_roots方法的典型用法代码示例。如果您正苦于以下问题:Python Poly.count_roots方法的具体用法?Python Poly.count_roots怎么用?Python Poly.count_roots使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.polys.Poly
的用法示例。
在下文中一共展示了Poly.count_roots方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: log_to_real
# 需要导入模块: from sympy.polys import Poly [as 别名]
# 或者: from sympy.polys.Poly import count_roots [as 别名]
def log_to_real(h, q, x, t):
"""
Convert complex logarithms to real functions.
Given real field K and polynomials h in K[t,x] and q in K[t],
returns real function f such that:
___
df d \ `
-- = -- ) a log(h(a, x))
dx dx /__,
a | q(a) = 0
Examples
========
>>> from sympy.integrals.rationaltools import log_to_real
>>> from sympy.abc import x, y
>>> from sympy import Poly, sqrt, S
>>> log_to_real(Poly(x + 3*y/2 + S(1)/2, x, domain='QQ[y]'),
... Poly(3*y**2 + 1, y, domain='ZZ'), x, y)
2*sqrt(3)*atan(2*sqrt(3)*x/3 + sqrt(3)/3)/3
>>> log_to_real(Poly(x**2 - 1, x, domain='ZZ'),
... Poly(-2*y + 1, y, domain='ZZ'), x, y)
log(x**2 - 1)/2
See Also
========
log_to_atan
"""
u, v = symbols('u,v', cls=Dummy)
H = h.as_expr().subs({t: u + I*v}).expand()
Q = q.as_expr().subs({t: u + I*v}).expand()
H_map = collect(H, I, evaluate=False)
Q_map = collect(Q, I, evaluate=False)
a, b = H_map.get(S(1), S(0)), H_map.get(I, S(0))
c, d = Q_map.get(S(1), S(0)), Q_map.get(I, S(0))
R = Poly(resultant(c, d, v), u)
R_u = roots(R, filter='R')
if len(R_u) != R.count_roots():
return None
result = S(0)
for r_u in R_u.keys():
C = Poly(c.subs({u: r_u}), v)
R_v = roots(C, filter='R')
if len(R_v) != C.count_roots():
return None
for r_v in R_v:
if not r_v.is_positive:
continue
D = d.subs({u: r_u, v: r_v})
if D.evalf(chop=True) != 0:
continue
A = Poly(a.subs({u: r_u, v: r_v}), x)
B = Poly(b.subs({u: r_u, v: r_v}), x)
AB = (A**2 + B**2).as_expr()
result += r_u*log(AB) + r_v*log_to_atan(A, B)
R_q = roots(q, filter='R')
if len(R_q) != q.count_roots():
return None
for r in R_q.keys():
result += r*log(h.as_expr().subs(t, r))
return result
示例2: log_to_real
# 需要导入模块: from sympy.polys import Poly [as 别名]
# 或者: from sympy.polys.Poly import count_roots [as 别名]
def log_to_real(h, q, x, t):
"""Convert complex logarithms to real functions.
Given real field K and polynomials h in K[t,x] and q in K[t],
returns real function f such that:
___
df d \ `
-- = -- ) a log(h(a, x))
dx dx /__,
a | q(a) = 0
"""
u, v = symbols('u,v')
H = h.as_expr().subs({t:u+I*v}).expand()
Q = q.as_expr().subs({t:u+I*v}).expand()
H_map = collect(H, I, evaluate=False)
Q_map = collect(Q, I, evaluate=False)
a, b = H_map.get(S(1), S(0)), H_map.get(I, S(0))
c, d = Q_map.get(S(1), S(0)), Q_map.get(I, S(0))
R = Poly(resultant(c, d, v), u)
R_u = roots(R, filter='R')
if len(R_u) != R.count_roots():
return None
result = S(0)
for r_u in R_u.iterkeys():
C = Poly(c.subs({u:r_u}), v)
R_v = roots(C, filter='R')
if len(R_v) != C.count_roots():
return None
for r_v in R_v:
if not r_v.is_positive:
continue
D = d.subs({u:r_u, v:r_v})
if D.evalf(chop=True) != 0:
continue
A = Poly(a.subs({u:r_u, v:r_v}), x)
B = Poly(b.subs({u:r_u, v:r_v}), x)
AB = (A**2 + B**2).as_expr()
result += r_u*log(AB) + r_v*log_to_atan(A, B)
R_q = roots(q, filter='R')
if len(R_q) != q.count_roots():
return None
for r in R_q.iterkeys():
result += r*log(h.as_expr().subs(t, r))
return result