sympy.bernoulli()方法
借助于sympy.bernoulli()方法,我们可以找到symy中的伯努利数和伯努利多项式。
bernoulli(n)
语法:bernoulli(n)
参数:
n –表示第n个伯努利数。
返回值: 返回第n个bernoulli数。
sympy.bernoulli()方法 例# 1:
# import sympy
from sympy import * n = 4
print("Value of n = {}".format(n))
# Use sympy.bernoulli() method
nth_bernoulli = bernoulli(n)
print("Value of nth bernoulli number : {}".format(nth_bernoulli))
输出:
Value of n = 4
Value of nth bernoulli number : -1/30
bernoulli(n, k)
语法:bernoulli(n, k)
参数:
n –表示伯努利多项式的阶数。
k –表示伯努利多项式中的变量。
返回值:返回伯努利多项式的表达式或其值。
sympy.bernoulli()方法 例# 2:
# import sympy
from sympy import * n = 5
k = symbols('x')
print("Value of n = {} and k = {}".format(n, k))
# Use sympy.bernoulli() method
nth_bernoulli_poly = bernoulli(n, k)
print("The nth bernoulli polynomial : {}".format(nth_bernoulli_poly))
输出:
Value of n = 5 and k = x
The nth bernoulli polynomial : x**5 - 5*x**4/2 + 5*x**3/3 - x/6
sympy.bernoulli()方法 示例# 3:
# import sympy
from sympy import * n = 4
k = 3
print("Value of n = {} and k = {}".format(n, k))
# Use sympy.bernoulli() method
nth_bernoulli_poly = bernoulli(n, k)
print("The nth bernoulli polynomial value : {}".format(nth_bell_poly))
输出:
Value of n = 4 and k = 3
The nth bernoulli polynomial value : 10*x1**2*x3 + 15*x1*x2**2