Advertisement
makispaiktis

Converging vs Diverging Series

Oct 12th, 2020 (edited)
2,497
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. from matplotlib import pyplot as plt
  2. from math import pi
  3.  
  4. LIMIT = 100
  5. x = list(range(1, LIMIT+1))
  6. SUM1 = 0
  7. sum1 = list()
  8. SUM2 = 0
  9. sum2 = list()
  10. CONSTANT = pi * pi / 6
  11. constant = [CONSTANT for i in range(1, LIMIT+1)]
  12. for i in x:
  13.     SUM1 += 1 / i
  14.     sum1.append(SUM1)
  15.     SUM2 += 1 / i**2
  16.     sum2.append(SUM2)
  17.  
  18. # About the plots
  19. print("sum1 = " + str(sum1))
  20. print("sum2 = " + str(sum2))
  21. print("constant = " + str(constant))
  22. plt.plot(x, sum1, label="Sum1 = Ξ£(1 / n)" + str(LIMIT))
  23. plt.plot(x, sum2, label="Sum2 = Ξ£(1 / n^2)" + str(LIMIT))
  24. plt.plot(x, constant, label="y = Ο€^2 / 6")
  25. plt.title("Sums of 1/n, 1/n^2 for the first " + str(LIMIT) + " terms")
  26. plt.legend()
  27. plt.show()
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement