%
% This code will test balanced reduction on 
% the CD Player.   The input tolerance  
% should be the desired error between output
% of reduced vs. full system
%


clear;
load CD.mat;
%tol = .01;
tol = input('truncation tolerance tol= ');

[Ak,Bk,Ck,s] = balS(A,B,C,tol);

n = size(A,1);
k =  size(Ak,1);

figure(1)
clf
e1 = 0; e2 = 7;
textstring = [ 'Freq-Response CD-Player :   \tau = ', num2str(tol),  ',  n = ', num2str(n), ' , k = ', num2str(k)];
Mysigma_log(A,B,C,D,e1,e2,textstring,'b');
hold
Mysigma_log(Ak,Bk,Ck,D,e1,e2,textstring,'r-.');
legend('Original', 'Reduced')

Dimension_Full_System = size(A,1) 
Dimension_Reduced_System =  size(Ak,1)


t = eig(A); s = eig(Ak);
figure(2)
clf

plot(real(t), imag(t), '*' ,'linewidth',2.5);
hold on

plot(real(s), imag(s), 'ro','linewidth',2.5);

hold off
