Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. c = [1,2,3]
  3. x = [0, 2, 4, 8]
  4.  
  5. def polynomial():
  6. for i in range(len(x)):
  7. ans = 0
  8. for n,a in enumerate(c): #uzycie enumarate
  9. ans = sum((a*x[i]**n, ans)) #uzycie sum
  10. yield ans
  11.  
  12. p = (list(polynomial()))
  13. print(p) #wynik sie zgadza
  14.  
  15.  
  16. #2
  17.  
  18. import matplotlib.pyplot as plt
  19. c = [1,2,3]
  20. x = [0, 2, 4, 8]
  21.  
  22. def polynomial():
  23. for i in range(len(x)):
  24. ans = 0
  25. for n,a in enumerate(c): #uzycie enumarate
  26. ans = sum((a*x[i]**n, ans)) #uzycie sum
  27. yield ans
  28.  
  29. p = (list(polynomial()))
  30. print(p) #wynik sie zgadza
  31.  
  32. n = 100
  33. xd = [8*x/100 for x in range(0,100)]
  34. y = [xd**2 for xd in xd]
  35.  
  36. plt.plot(x,p)
  37. plt.plot(xd,y)
  38.  
  39. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement