Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. import numpy as np
  2. from pylab import *
  3.  
  4. a2 = -4.65
  5. a1 = 5.625
  6. a0 = -2.025
  7. A = np.matrix([[-a2, -a1, -a0], [1, 0, 0], [0, 1, 0]])
  8. B = np.matrix([[1], [0], [0]])
  9. C = np.matrix([1, 1, 1])
  10.  
  11. def odpSkokowa(A,B,C):
  12. x = np.matrix([[0], [0], [0]])
  13. y = []
  14. for n in range(30):
  15. y.append((C*x).item(0))
  16. x = A*x + B
  17. return y
  18.  
  19. subplot(2,1,1)
  20. plot(odpSkokowa(A,B,C))
  21.  
  22.  
  23. def sterowanieOptymalne(A,B,C,c1,c2):
  24. Q = c1*np.eye(3)
  25. R = c2
  26. P = np.matrix([[0,0,0],[0,0,0],[0,0,0]])
  27. for n in range(30):
  28. P = Q + np.transpose(A)* (P - P*B* (R + np.transpose(B)*P*B)**(-1) * np.transpose(B)*P)*A
  29. F = (R + np.transpose(B)*P*B)**(-1)*np.transpose(B)*P*A
  30. return F
  31.  
  32. def odpSkokowaXXX(A,B,C):
  33. x = np.matrix([[0], [0], [0]])
  34. xk = []
  35. y = []
  36. for n in range(30):
  37. y.append((C*x).item(0))
  38. x = A*x + B
  39. xk.append((-sterowanieOptymalne(A,B,C,1,5)*x).item(0))
  40. return xk
  41.  
  42. subplot(2,1,2)
  43. plot(odpSkokowa(A-B*sterowanieOptymalne(A,B,C,1,5), B, C), 'og')
  44. plot(odpSkokowaXXX(A-B*sterowanieOptymalne(A,B,C,1,5), B, C), 'ob')
  45. show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement