%  Example 6.9.  Generate a root locus for a LQR system as the control
%    weighting in the cost function is varied.
clear
%  Define the plant model.
A=[1 -1
   3 -4];
B=[1 0]';
C=[1 0];
%  Compute the plant poles and zeros.
[nu,de]=ss2tf(A,B,C,0);
zeros=roots(nu)
poles=roots(de)
%  Define the state weighting matrix.
Q=C'*C;
%  Define the values to be used for control weighting.
Rvec=logspace(-2,1,50);
%  Generate the closed loop pole locations for each R.
for i=1:50,
  [K,S,E]=lqr(A,B,Q,Rvec(i));
  pole_k(i,:)=E';
end
%  Plot the results.
set(0,'DefaultAxesFontName','times')
set(0,'DefaultAxesFontSize',16)
set(0,'DefaultTextFontName','times')
figure(1)
clf
plot(real(pole_k),imag(pole_k),'x')
xlabel('Real axis')
ylabel('Imaginary axis')
grid
