Python sympy.div()方法
函数div()提供有余数的多项式的除法。也就是说,对于多项式f和g,它计算q和r,使f= g*q+r并且deg(r)<q。
语法: sympy.div(f, g, domain='QQ')
返回: 多项式有余数的除法.
示例 #1:
# import sympy
from sympy import *
f = 5 * x**2 + 10 * x + 3
g = 2 * x + 2
# Using sympy.div() method
q, r = div(f, g, domain ='QQ')
print(q)
print(r)
输出:
5*x/2 + 5/2
-2
示例 #2:
# import sympy
from sympy import *
f = 5 * x**2 + 10 * x + 3
g = 2 * x**2 + 2
# Using sympy.div() method
q, r = div(f, g, domain ='QQ')
print(q)
print(r)
输出:
5/2
10*x - 2