Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4. T = 100
  5. h = 0.01
  6.  
  7. a=1.5 #a ma być >0!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!11
  8. y_max=70
  9. temp=22
  10. y_min=10
  11. M=3
  12.  
  13. #schemat Eulera: x = x + h * (f)
  14.  
  15. t = np.arange(0,T,h)
  16. x = np.ones(t.size)
  17. e = np.ones(t.size)
  18. u = np.zeros(t.size)
  19.  
  20. x[0]=1
  21. e[0]=temp-x[0]
  22. for i in range(t.size - 1):
  23.     e[i+1] = temp-x[i]
  24.     print(e[i])
  25.  
  26.     if e[i+1]>M:
  27.         u[i+1]=y_max
  28.     elif e[i+1]<-M:
  29.         u[i+1]=y_min
  30.     elif e[i+1]>=-M or e[i+1]<M:
  31.         u[i+1]=temp
  32.  
  33.     #x[i + 1] = x[i] + h * (a* x[i] + u[i])
  34.     x[i + 1] = x[i] + h * ((u[i]-x[i])/a)
  35.  
  36. plt.subplot(311)
  37. plt.plot(t, x, label='x')
  38. plt.hlines(temp,0, T,'r', 'dashed') # temp, rysuj od 0, do T, red, dashed
  39. plt.legend(loc='upper right')
  40. plt.xlabel('t')
  41. plt.ylabel('x')
  42. #plt.axis([40, 47, y_min, y_max])
  43. plt.axis([0, 10, temp-2, temp+2])
  44.  
  45. #plt.ylim([0, 7])
  46. plt.subplot(312)
  47. plt.plot(t, e, label='e')
  48. plt.legend(loc='upper right')
  49. plt.xlabel('t')
  50. plt.ylabel('e')
  51. plt.hlines(0,0, T,'r', 'dashed')
  52. plt.axis([0, 100, -10, 5])
  53.  
  54. plt.subplot(313)
  55. plt.plot(t, u, label='u')
  56. plt.legend(loc='upper right')
  57. plt.xlabel('t')
  58. plt.ylabel('u')
  59. plt.axis([0, 100, y_min-5, y_max+5])
  60.  
  61. plt.show()
  62.  
  63. #histereza, wytłumaczenie jak działa
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement