Python sympy.factor_list()方法

Python sympy.factor_list()方法

sympy.factor_list()方法的帮助下,我们可以在SymPy中以(factor, power)元组的形式获得一个数学表达式的因子列表。

语法: factor_list(expression)

参数:
expression – 它是一个数学表达式。

返回:以(因子,幂)元组的形式返回给定数学表达式的因子列表。

示例 #1:
在这个例子中,我们可以看到,通过使用sympy.factor_list()方法,我们可以得到一个给定数学表达式的因子列表。

# import sympy
from sympy import * x = symbols('x')
expr = x**2 * z + 4 * x*y * z + 4 * y**2 * z
  
print("Mathematical expression : {}".format(expr))
    
# Use sympy.factor_list() method
f = factor_list(expr) 
    
print("List of factors : {}".format(f)) 

输出:

Mathematical expression : x**2*z + 4*x*y*z + 4*y**2*z
List of factors : (1, [(z, 1), (x + 2*y, 2)])

示例 #2:

# import sympy
from sympy import * x = symbols('x')
expr = (x**2 - 2 * x + 1)
  
print("Mathematical expression : {}".format(expr))
    
# Use sympy.factor_list() method
f = factor_list(expr) 
    
print("List of factors : {}".format(f)) 

输出:

Mathematical expression : x**2 - 2*x + 1
List of factors : (1, [(x - 1, 2)])

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程