%Example 8.10
% RS of spinning satellite 
clear all;close all;
%Plant (3.78):
alpha = 10;
a = [0 alpha ; -alpha 0];
b = [1 0; 0 1];
c = [1 alpha; -alpha 1];
d = [ 0 0;  0 0];
G = pck(a,b,c,d);

I2 = eye(2);
K=I2;

% KG and GK are both equal to G
L = mmult(G,K); 
S = minv(madd(I2,L)); 
T = msub(I2,S); 

omega=logspace(-2,2,41);
Tf=frsp(T,omega);

% Get same value for mu indeoendent of perturbations.

disp('Full-block uncertainty:');
uncblk=[2 2];
[mubounds,rowd,sens,rowp,rowd]=mu(Tf,uncblk);
[pk,pkomega,vindex]=pkvnorm(mubounds,inf)

%Figure 8.12
vplot('liv,lm',mubounds,'y',1,'w:');
xlabel('Frequency'); ylabel('Magnitude');
axis ([0.01 100, 1e-6,20]);hold on;drawnow;

disp('Diagonal uncertainty:');
uncblk=[1 1; 1 1];
[mubounds,rowd,sens,rowp,rowd]=mu(Tf,uncblk);
vplot('liv,lm',mubounds,'g');drawnow;
[pk,pkomega,vindex]=pkvnorm(mubounds,inf)

disp('Repeated complex scalar uncertainty:');
uncblk=[2 0];
[mubounds,rowd,sens,rowp,rowd]=mu(Tf,uncblk);
vplot('liv,lm',mubounds,'b');drawnow;
[pk,pkomega,vindex]=pkvnorm(mubounds,inf)

disp('Repeated real scalar uncertainty:');
uncblk=[-2 0];
[mubounds,rowd,sens,rowp,rowd]=mu(Tf,uncblk);
vplot('liv,lm',mubounds,'r');hold off
[pk,pkomega,vindex]=pkvnorm(mubounds,inf)


