Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4. a0 = -0.675
  5. a1 = 3.675
  6. a2 = -4.15
  7. u = 1
  8.  
  9. c1 = 100
  10. c2 = 0.5
  11.  
  12. A = np.matrix([[-a2, -a1, -a0], [1, 0, 0], [0, 1, 0]])
  13. B = np.matrix([[1], [0], [0]])
  14. C = np.matrix([1, 1, 1])
  15. D = np.matrix([0])
  16.  
  17. x = x2 = xk = np.matrix([[0], [0], [0]])
  18. y = y2 = []
  19.  
  20.  
  21. def odpowiedz_skokowa ():
  22. for i in range(0, 20):
  23. global x, y
  24. y = np.append(y, C * x + D * u)
  25. x = (A*x + B * u)
  26.  
  27. n = np.arange(len(y))
  28. plt.figure(1)
  29. plt.subplot(421)
  30. plt.plot(n, y, 'rx')
  31.  
  32. return x
  33.  
  34.  
  35. def sterownik (c1, c2):
  36. Q = c1 * np.eye(3)
  37. R = c2
  38. P = np.eye(3)
  39.  
  40. for i in range(0, 20):
  41. P = Q + np.transpose(A) * (P - P * B * (R + np.transpose(B) * P * B) ** (-1) * np.transpose(B)*P) * A
  42.  
  43.  
  44. global xk
  45. F = (R + np.transpose(B) * P * B)**(-1) * np.transpose(B) * P * A
  46.  
  47. uk=[[0]]
  48.  
  49. A_nowe = A - B * F
  50.  
  51. global x2, y2
  52.  
  53. for i in range(0, 20):
  54. x2 =( A_nowe * x2 + B * u)
  55. y2 = np.append(y2, C * x2 + D * u)
  56. uk = np.append(uk, - (F * x2))
  57.  
  58.  
  59. return [y2, uk]
  60.  
  61. odpowiedz_skokowa()
  62.  
  63. # Dla sterownika o c1 = 100, c2 = 0.5
  64.  
  65. sterownik_1 = sterownik(100, 0.5)
  66.  
  67. plt.figure(1)
  68. plt.subplot(423)
  69. plt.plot(sterownik_1[0], 'rx')
  70. plt.subplot(424)
  71. plt.plot(sterownik_1[1], 'rx')
  72.  
  73.  
  74. # Dla sterownika o c1 = 100, c2 = 0.5
  75.  
  76. sterownik_2 = sterownik(20, 25)
  77. plt.subplot(425)
  78. plt.plot(sterownik_2[0], 'rx')
  79. plt.subplot(426)
  80. plt.plot(sterownik_2[1], 'rx')
  81.  
  82.  
  83. # Dla sterownika o c1 = 100, c2 = 0.5
  84.  
  85. sterownik_3 = sterownik(50, 10)
  86. plt.subplot(427)
  87. plt.plot(sterownik_3[0], 'rx')
  88. plt.subplot(428)
  89. plt.plot(sterownik_3[1], 'rx')
  90.  
  91.  
  92. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement