📜  Python| sympy.bell() 方法

📅  最后修改于: 2022-05-13 01:54:48.090000             🧑  作者: Mango

Python| sympy.bell() 方法

借助sympy.bell()方法,我们可以在 SymPy 中找到贝尔数和贝尔多项式。

钟(n) -

示例 #1:

# import sympy 
from sympy import * n = 5
print("Value of n = {}".format(n))
   
# Use sympy.bell() method 
nth_bell = bell(n)  
      
print("Value of nth bell number : {}".format(nth_bell))  

输出:

Value of n = 5
Value of nth bell number : 52

钟(n,k)——

示例 #2:

# import sympy 
from sympy import * n = 5
k = symbols('x')
print("Value of n = {} and k = {}".format(n, k))
   
# Use sympy.bell() method 
nth_bell_poly = bell(n, k)  
      
print("The nth bell polynomial : {}".format(nth_bell_poly))  

输出:

Value of n = 5 and k = x
The nth bell polynomial : x**5 + 10*x**4 + 25*x**3 + 15*x**2 + x

示例#3:

# import sympy 
from sympy import * n = 5
k = 3
print("Value of n = {} and k = {}".format(n, k))
   
# Use sympy.bell() method 
nth_bell_poly = bell(n, k)  
      
print("The nth bell polynomial value : {}".format(nth_bell_poly))  

输出:

Value of n = 5 and k = 3
The nth bell polynomial value : 1866

钟(n,k,(x1,x2,x3,…))——

示例 #4:

# import sympy 
from sympy import * n = 5
k = 3
variables = symbols('x:6')[1:]
print("Value of n = {}, k = {} and variables = {}".format(n, k, variables))
   
# Use sympy.bell() method 
nth_bell_poly = bell(n, k, variables)  
      
print("The nth bell polynomial of second kind : {}".format(nth_bell_poly))  

输出:

Value of n = 5, k = 3 and variables = (x1, x2, x3, x4, x5)
The nth bell polynomial of second kind : 10*x1**2*x3 + 15*x1*x2**2