Python | sympy.harmonic() method
With the help of sympy.harmonic() method, we can find Harmonic numbers in SymPy.
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:
# import sympy from sympy import * n = 7print("Value of n = {}".format(n)) # Use sympy.harmonic() method 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
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:
# import sympy from sympy import * n = 5m = 2print("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)) |
Output:
Value of n = 5 and m = 2 The nth harmonic number of order m : 5269/3600
Recommended Posts:
- class method vs static method in Python
- Python | os.dup() method
- Python | set() method
- Python | next() method
- Python | bytes() method
- Python | shutil.which() method
- Python | os.sched_get_priority_min() method
- Python | os.sched_getaffinity() method
- Python | os.sched_setaffinity() method
- Python | sympy.sin() method
- Python | after method in Tkinter
- Python | os.getcwd() method
- Python | os.ftruncate() method
- Python | os.truncate() method
- Python | sympy.cos() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



