📜  Python| sympy.harmonic() 方法

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

Python| sympy.harmonic() 方法

借助sympy.harmonic()方法,我们可以在 SymPy 中找到谐波数。

谐波(n)

n谐波数由下式给出 - \operatorname{H}_{n} = 1 + \frac{1}{2} + \frac{1}{3} + \ldots + \frac{1}{n} .

示例 #1:

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

输出:

Value of n = 7
Value of nth harmonic number : 363/140
谐波(n, m)

m阶的第n广义谐波数由下式给出 - \operatorname{H}_{n, m} = \sum_{k=1}^{n} \frac{1}{k^m} .

示例 #2:

# import sympy 
from sympy import * 
  
n = 5
m = 2
print("Value of n = {} and m = {}".format(n, m))
   
# Use sympy.harmonic() method 
nth_harmonic_poly = harmonic(n, m)  
      
print("The nth harmonic number of order m : {}".format(nth_harmonic_poly))  

输出:

Value of n = 5 and m = 2
The nth harmonic number of order m : 5269/3600