Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. import math
  4. y0 = 5 #temp poczatakowa
  5. a = 1.5
  6. T = 8
  7. h = 0.01
  8. y_set = 22 # t* temp zadane
  9. u_max = 70
  10. u_min = 10
  11. d = 0.2
  12. M = 0.25
  13.  
  14. def fu(e):
  15. if (e >= M + d):
  16. return u_max
  17. if (e < M + d and e >= -M - d):
  18. return y_set
  19. if (e < -M - d):
  20. return u_min
  21.  
  22. t = np.arange(0, T, h)
  23. y = np.empty(t.size)
  24. us = np.empty(t.size)
  25. es = np.empty(t.size)
  26.  
  27. y[0] = y0
  28. us[0] = y_set
  29. es[0] = y_set - y[0]
  30.  
  31. for i in range(0, t.size-1):
  32. es[i+1] = y_set - y[i]
  33. us[i + 1] = fu(es[i+1])
  34. y[i + 1] = y[i] + h * ((us[i] - y[i])/a)
  35.  
  36. plt.figure(1)
  37. plt.subplots_adjust(hspace = 0.4)
  38. plt.subplot(311)
  39. plt.xlabel("t")
  40. plt.ylabel("e(t)")
  41. plt.plot(t, es, 'o-', markersize=1)
  42. # plt.hlines(0,0, T,'r','dashed')
  43. #plt.axis([20, 100, -20, 50])
  44.  
  45.  
  46. plt.subplot(312)
  47. plt.plot(t, y, 'r-', markersize=1)
  48. plt.xlabel("t")
  49. plt.ylabel("y(t)")
  50. # plt.hlines(d+ M + y_set,0, T,'y' ,'dashed')
  51. # plt.hlines(y_set, 0, T, 'b', 'dashed')
  52. # plt.hlines(y_set - M -d,0, T,'y' ,'dashed')
  53. # plt.axis([0, 100, 120, 200])
  54.  
  55.  
  56. plt.subplot(313)
  57. plt.plot(t, us, 'r-', markersize=1)
  58. plt.xlabel("t")
  59. plt.ylabel("u(t)")
  60.  
  61. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement