當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python sympy.bell()用法及代碼示例

借助於sympy.bell()方法,我們可以在SymPy中找到Bell數和Bell多項式。

bell(n) -


用法: bell(n) 

參數:
n -它表示鈴聲編號的順序。

返回:返回nth響鈴號碼。

範例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

bell(n, k) -

用法: bell(n, k) 

參數:
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

bell(n, k, (x1, x2, x3, …)) -

用法: bell(n, k, (x1, x2, x3, …)) 

參數:
n -它表示第二種鍾形多項式的階數。
k -它是第二種鍾形多項式中的一個參數。
(x1,x2,x3,...)-它表示可變符號的元組。

返回:返回第二類的Bell多項式。

範例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


相關用法


注:本文由純淨天空篩選整理自rupesh_rao大神的英文原創作品 Python | sympy.bell() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。