Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.43 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3.  
  4.  
  5. def przelacznik2polozeniowy(e):
  6.     if(e>0):
  7.         return 22
  8.     return 0
  9.  
  10. def przelacznik2polozeniowyZHistereza(e, uPoprzednie):
  11.     if(e>1):
  12.         return 30
  13.     elif (e<-1):
  14.         return 0
  15.     return uPoprzednie
  16.  
  17. def przelacznik3polozeniowy(e, uPoprzednie):
  18.     if(e>0):
  19.         return 17
  20.     elif (e<0):
  21.         return -17
  22.     return 0
  23.  
  24. def przelacznik3polozeniowyZHistereza(e, uPoprzednie, h):
  25.     if(e>h):
  26.         return 17
  27.     elif (e<-h):
  28.         return -17
  29.     elif((e>0 and uPoprzednie>0) or (e<0 and uPoprzednie<0)):
  30.         return uPoprzednie
  31.     return 0
  32.  
  33.  
  34. zadana = 5
  35.  
  36. T = 10
  37. deltaT = 0.1
  38. t = np.arange(0., T, deltaT)
  39.  
  40. y = np.empty_like(t)
  41. y[0] = 10
  42.  
  43. e = np.empty_like(t)
  44. e[0]=zadana-y[0]
  45.  
  46. e_kw=np.empty_like(t)
  47. e_kw[0]=e[0]*e[0]*deltaT
  48. sum=e_kw[0]
  49.  
  50. u = np.empty_like(t)
  51. u[0] = przelacznik3polozeniowy(e[0],0)
  52.  
  53. for h in range(1,5):
  54.     for i in range(len(t) - 1):
  55.         y[i + 1] = y[i] + deltaT * (-3 * y[i] + u[i]-1)
  56.         e[i+1]=zadana-y[i+1]
  57.         sum+=((zadana-y[i+1])*(zadana-y[i+1]))*deltaT
  58.         e_kw[i+1] = sum
  59.         u[i+1]=przelacznik3polozeniowyZHistereza(e[i+1],u[i],h/10)
  60.     plt.subplot(211)
  61.     plt.plot(e_kw,t)
  62.     plt.subplot(212)
  63.     plt.plot(t,e)
  64. plt.show()
  65.  
  66.  
  67. # plt.subplot(311)
  68. # plt.plot(t,e)
  69. # plt.axhline(0,color="k")
  70. # plt.subplot(312)
  71. # plt.plot(t,u)
  72. # plt.plot(t,e_kw)
  73. # plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement