Program to plot Harmonic Progression series in Python

Program to plot Harmonic Progression series in Python

In this, we discuss Harmonic Progression series and check how to plot Harmonic Progression series in Python Programming using Matplotlib.

Numpy and Matplotlib to Plot the graph of Harmonic Progression.If you want to know about the Harmonic progression series in detail then check the post given below:

If you are new to Python Programming also check the list of topics given below. So that you can easily understand the Program to Plot Harmonic progression series. Also check the program how to print Harmonic Progression Series




After learning all these topic now we moved to Plot the Harmonic Progression series.

Python Code:
# HP seriesimport numpy as np
from matplotlib import pyplot as plt
r = []
a = int(input('enter first term'))
d = int(input('enter common difference'))
n = int(input('enter number of terms'))
y = np.linspace(1,n,n,dtype= int)
print('HP series is:')
i = 1while(i<=n):
    cr = a+(i-1)*d
    tr = 1/(a+ (i-1)*d)
    s = str('1')+'/'+str(cr)
    r.append(tr)
    print(s)
    i = i+1print(r)
plt.plot(y,r,'ro')
plt.xlabel('position of terms')
plt.ylabel('values of terms')
plt.title('Graph of H.P Series')
plt.show()
Output:

enter first term 1
enter common difference 2
enter number of terms 6
HP series is:
1/1
1/3
1/5
1/7
1/9
1/11
[1.0, 0.3333333333333333, 0.2, 0.14285714285714285, 0.1111111111111111, 0.09090909090909091]