Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. from numpy import *
  3. import matplotlib.pyplot as plt
  4. import math
  5. import pylab
  6. from matplotlib import mlab
  7.  
  8. print("Строитель графиков")
  9.  
  10. f = input ('f(x)=')
  11. code = """
  12. def func (x):
  13. return %s
  14. """ % f
  15. exec(code)
  16.  
  17. xmin = -20.0
  18. xmax = 20
  19. dx = 0.01
  20. xlist = mlab.frange (xmin, xmax, dx)
  21. ylist = [func (x) for x in xlist]
  22. plt.axis([-20, 20, -20, 20])
  23. plt.xlabel('x')
  24. plt.ylabel('y')
  25. plt.title('График функции(x)')
  26. plt.grid(True)
  27. pylab.plot (xlist, ylist)
  28. pylab.show()
  29.  
  30. code = """
  31. def func (x):
  32. return %s
  33. """ % f
  34.  
  35. # -*- coding: utf-8 -*-
  36. import numexpr as ne
  37. import matplotlib.pyplot as plt
  38. from matplotlib import mlab
  39.  
  40. plt.style.use('ggplot')
  41.  
  42. xmin = -20.0
  43. xmax = 20
  44. dx = 0.01
  45. x = mlab.frange(xmin, xmax, dx)
  46.  
  47. # f = input ('f(x)=')
  48. f = "x**2 * sin(x)"
  49. plt.plot(x, ne.evaluate(f), linewidth=1.5)
  50. plt.xlabel('x')
  51. plt.ylabel('y')
  52. plt.legend(['График функции: f(x) = {}'.format(f)])
  53. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement