📜  Python| sympy.tribonacci() 方法

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

Python| sympy.tribonacci() 方法

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

tribonacci(n) -


Tribonacci 数是由初始项定义的整数序列T_0 = 0 , T_1 = 1 , T_2 = 1和三项递推关系T_n = T_{n-1} + T_{n-2} + T_{n-3} .

示例 #1:

# import sympy 
from sympy import * 
  
n = 7
print("Value of n = {}".format(n))
   
# Use sympy.tribonacci() method 
nth_tribonacci = tribonacci(n)  
      
print("Value of nth tribonacci number : {}".format(nth_tribonacci))  

输出:

Value of n = 7
Value of nth tribonacci number : 24

tribonacci(n, k) -

Tribonacci 多项式定义为T_0(k) = 0 , T_1(k) = 1 , T_2(k) = k^2T_n(k) = k^2 T_{n-1}(k) + k T_{n-2}(k) + T_{n-3}(k)为了n > 2 .对于所有正整数n , T_n(1) = T_n .

示例 #2:

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

输出:

Value of n = 5 and k = x
The nth tribonacci polynomial : x**8 + 3*x**5 + 3*x**2

示例#3:

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

输出:

Value of n = 6 and k = 3
The nth tribonacci polynomial value : 68289