Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. clear all;
  2. clc;
  3. display('------------Linear Quadratic Regulator-----------------')
  4. % Define the matrix A, B, C, D
  5. A=[0,1,0,0;0,-42.44,212.24,0;0,0,0,1;0,0,0,-42.44];
  6. B=[0,0;106.12,-5;0,0;78.6,-42.44];
  7. C=[1,0,0,0;0,1,0,0;0,0,1,0;0,0,0,1];
  8. D=[0];
  9.  
  10. %Detect the controllability of the Given system
  11. Qc= ctrb(A,B);
  12. rank_of_Qc = rank(Qc)
  13.  
  14. %calculate the K to by using function K = lqr( A, B, Q, R)
  15. x = 2;
  16. Q = diag([x 0 0 0]);
  17. R=[1,0;0,1];
  18. K=lqr(A,B,Q,R)
  19.  
  20. %Find step response of LQR controller
  21. LQRcontroller_sys=ss((A-B*K),B,C,D) %Generating the closed loop state space model
  22. t=0:0.1:10;
  23. step(LQRcontroller_sys,t)
  24. grid on;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement