Advertisement
makispaiktis

Drawing Functions - Part 2

Apr 25th, 2020 (edited)
653
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. from math import log
  2.  
  3. # Create the 2 basic functions f(n) and g(n)
  4. f = lambda n : n**2
  5. g = lambda n : n**3
  6. logf = lambda n : log(f(n), 2)
  7. logg = lambda n : log(g(n), 2)
  8. expf = lambda n : 2**f(n)
  9. expg = lambda n : 2**g(n)
  10.  
  11. import matplotlib.pyplot as plt
  12. numbers = list(range(1, 11))
  13. # numbers = [1, 2, 3, .... , 9, 10]
  14. # 1st plot
  15. plt.plot([f(n) for n in numbers], label="f(n) = n^2")
  16. plt.plot([g(n) for n in numbers], label="g(n) = n^3")
  17. plt.xlabel("n")
  18. plt.ylabel("T(n)")
  19. plt.legend()
  20. plt.show()
  21. # 2nd plot
  22. plt.plot([logf(n) for n in numbers], label="logf(n) = log(n^2)")
  23. plt.plot([logg(n) for n in numbers], label="logg(n) = log(n^3)")
  24. plt.xlabel("n")
  25. plt.ylabel("T(n)")
  26. plt.legend()
  27. plt.show()
  28. # 3rd plot
  29. plt.plot([expf(n) for n in numbers], label="2 ^ f(n) = 2 ^ (n^2)")
  30. plt.plot([expg(n) for n in numbers], label="2 ^ g(n) = 2 ^ (n^3)")
  31. plt.xlabel("n")
  32. plt.ylabel("T(n)")
  33. plt.legend()
  34. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement