Python | sympy.harmonic() method
Last Updated :
14 Jul, 2019
With the help of
sympy.harmonic() method, we can find
Harmonic numbers in SymPy.
harmonic(n)
The
nth harmonic number is given by –
.
Syntax: harmonic(n)
Parameter:
n – It denotes the number upto which harmonic number is to be calculated.
Returns: Returns the nth harmonic number.
Example #1:
from sympy import *
n = 7
print ( "Value of n = {}" . format (n))
nth_harmonic = harmonic(n)
print ( "Value of nth harmonic number : {}" . format (nth_harmonic))
|
Output:
Value of n = 7
Value of nth harmonic number : 363/140
harmonic(n, m)
The
nth generalized harmonic number of order
m is given by –
.
Syntax: harmonic(n, m)
Parameter:
n – It denotes the number upto which harmonic number is to be calculated.
m – It denotes the order of the harmonic number.
Returns: Returns the nth harmonic number of order m.
Example #2:
from sympy import *
n = 5
m = 2
print ( "Value of n = {} and m = {}" . format (n, m))
nth_harmonic_poly = harmonic(n, m)
print ( "The nth harmonic number of order m : {}" . format (nth_harmonic_poly))
|
Output:
Value of n = 5 and m = 2
The nth harmonic number of order m : 5269/3600
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...