Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from matplotlib import pyplot as plt
- from math import pi
- LIMIT = 100
- x = list(range(1, LIMIT+1))
- SUM1 = 0
- sum1 = list()
- SUM2 = 0
- sum2 = list()
- CONSTANT = pi * pi / 6
- constant = [CONSTANT for i in range(1, LIMIT+1)]
- for i in x:
- SUM1 += 1 / i
- sum1.append(SUM1)
- SUM2 += 1 / i**2
- sum2.append(SUM2)
- # About the plots
- print("sum1 = " + str(sum1))
- print("sum2 = " + str(sum2))
- print("constant = " + str(constant))
- plt.plot(x, sum1, label="Sum1 = Σ(1 / n)" + str(LIMIT))
- plt.plot(x, sum2, label="Sum2 = Σ(1 / n^2)" + str(LIMIT))
- plt.plot(x, constant, label="y = π^2 / 6")
- plt.title("Sums of 1/n, 1/n^2 for the first " + str(LIMIT) + " terms")
- plt.legend()
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement