1.因式分解
例1:分解下列多项式
代码如下:
from sympy import symbols, factor x, y = symbols('x y') f = 3 * x ** 4 - 2 * x ** 3 * y + 3 * x ** 3 - x ** 2 * y ** 2 - 2 * x ** 2 * y + 6 * x ** 2 - x * y ** 2 - 4 * x * y - 2 * y ** 2 print(factor(f))
运行结果:
2.多项式展开
例2:展开下列多项式
代码如下:
from sympy import symbols, expand x, y = symbols('x y') f = (x + y) ** 3 print(expand(f))
运行结果:
3.分式化简
例3:化简下列分式
代码如下:
from sympy import symbols, cancel x = symbols('x') f = (x ** 2 + 2 * x + 1) / (x ** 2 + x) p = 1 / x + (3 * x / 2 - 2) / (x - 4) print(cancel(f)) print(cancel(p))
运行结果:
4.分式展开
例4:展开下列分式
代码如下:
from sympy import symbols, apart x = symbols('x') f = (4 * x ** 3 + 21 * x ** 2 + 10 * x + 12) / (x ** 4 + 5 * x ** 3 + 5 * x ** 2 + 4 * x) print(apart(f))
运行结果: