Advertisement
makispaiktis

Drawing Functions

Apr 25th, 2020 (edited)
534
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. from math import log, sqrt
  2.  
  3. # Declaring the 4 functions
  4. f1 = lambda n: n**2.5
  5. f2 = lambda n: sqrt(n)
  6. f3 = lambda n: n**2 + 10
  7. f4 = lambda n: (n**2) * log(n, 2)
  8.  
  9. numbers = list(range(1, 101))
  10. # numbers = [1, 2, 3, .... , 99, 100]
  11. f1Values = [f1(n) for n in numbers]
  12. f2Values = [f2(n) for n in numbers]
  13. f3Values = [f3(n) for n in numbers]
  14. f4Values = [f4(n) for n in numbers]
  15.  
  16. import matplotlib.pyplot as plt
  17. plt.plot(numbers, f1Values, label="f1(n) = n ^ 2.5")
  18. plt.plot(numbers, f2Values, label="f2(n) = sqrt(n)")
  19. plt.plot(numbers, f3Values, label="f3(n) = n ^ 2 + 10")
  20. plt.plot(numbers, f4Values, label="f4(n) = n ^ 2 * logn")
  21. plt.xlabel("n")
  22. plt.ylabel("f(n)")
  23. plt.legend()
  24. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement