Python| sympy.tribonacci() 方法
借助sympy.tribonacci()方法,我们可以在 SymPy 中找到 Tribonacci 数和 Tribonacci 多项式。
tribonacci(n) -
Tribonacci 数是由初始项定义的整数序列 , , 和三项递推关系 .
Syntax: tribonacci(n)
Parameter:
n – It denotes the number upto which Tribonacci number is to be calculated.
Returns: Returns the nth Tribonacci number.
示例 #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 多项式定义为 , , 和为了 .对于所有正整数 , .
Syntax: tribonacci(n, k)
Parameter:
n – It denotes the nth Tribonacci polynomial.
k – It denotes the variable in the Tribonacci polynomial.
Returns: Returns the nth Tribonacci polynomial in k, Tn(k)
示例 #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