close all % close all old plots

% state feedback control of motor - pole placement design.
A=[-10 0;1 0];
B=[100;0];
C=[0 1];
D=0;
P=ss(A,B,C,D);

% open-loop step response
figure(1)
step(P)

% prepare figure for closed-loop step responses
figure(2)
hold on

s=tf('s'); % this is how the Laplace variable is defined

z=.9; % relative damping. Let's try and change this one as well.
for w=[1 2 5 10] % evaluate for some different closed-loop speeds

   
    Pchar=s^2+2*z*w*s+w^2;  % characteristic polynomial to match
    p=zero(Pchar); % desired closed loop poles
    
    L=place(A,B,p); % pole Placement (type 'help place')
    
    % closed-loop system
    G=ss(A-B*L,B,C,D);
    lr=1/dcgain(G); % set lr to achieve r=y in stationarity
    G=ss(A-B*L,B*lr,C,D); % now with unity gain from r to y
    
    % plot step response
    step(G)
    
    % why do we not always juse w=1, (or even smaller - i.e. faster - w)?
end

