%
% ---------------------------------------------------------------
%  MUPLT.M is a script file that produces the plots for the ACC
%     Benchmark problem.
% ---------------------------------------------------------------
%

% R. Y. Chiang & M. G. Safonov 
% Copyright (c) 1988 by the MathWorks, Inc.
% All Rights Reserved.
   subplot
   subplot(211)
   semilogx(w,[perttw1;pertt1]);
   title('Ty1u1 in "s~" and "s"');
   grid;xlabel('Rad/Sec'); ylabel('PERRON SSV (db)');
   text(0.002,-5,['MSM in s~: +-',num2str(msmw1),' %']);
   text(0.002,-10,['MSM in s : +-',num2str(msm1),' %']);

   subplot(212)
   semilogx(w,[perttw;pertt]);
   title('Ty1u1 in "s~" and "s"');
   grid;xlabel('Rad/Sec'); ylabel('PERRON SSV (db)');
   text(0.002,-5,['MSM in s~: +-',num2str(msmw),' %']);
   text(0.002,-10,['MSM in s : +-',num2str(msm),' %']);
   pause
   ptid = input(' Do you want a hardcopy ? (1=yes,0=no)');
   if ptid == 1
     print
   end

   subplot
   subplot(221)
   loglog(w,exp(diag_d))
   title('Diagonal Scaling D(s)')
   xlabel('Rad/Sec')
   ylabel('logd')

   subplot(222)
   loglog(w,exp(diag_d(1,:)),'x',w,ga1);
   title('D11(s)')
   xlabel('R/S (x: data; solid: fit)')
   ylabel('logd')

   subplot(223)
   loglog(w,exp(diag_d(2,:)),'x',w,ga2);
   title('D22(s)')
   xlabel('R/S (x: data; solid: fit)')  
   ylabel('logd')
      
   subplot(224)
   loglog(w,exp(diag_d(3,:)),'x',w,ga3);
   title('D33(s)')
   xlabel('R/S (x: data; solid: fit)')
   ylabel('logd')
   ptid = input(' Do you want a hardcopy ? (1=yes,0=no)');
   if ptid == 1
     print
   end
   pause

   subplot
   subplot(221)
   plot(t,x1_ipw1);grid;
   title('x1');       xlabel('Sec')

   subplot(222)
   plot(t,x2_ipw1);grid;
   title('x2 (z)');   xlabel('Sec');

   subplot(223)
   plot(t,u_ipw1); grid;
   title('Control (u)'); xlabel('Sec');

   subplot(224)
   text(0.6,0.4,'Impulse Response @ M1','sc');
   text(0.6,0.35,'Sensor Noise: 0.001*sin(100t)','sc')
   text(0.65,0.3,'Dashed: k = 0.5','sc');
   text(0.65,0.25,'Solid:  k = 1.0','sc');
   text(0.65,0.2,'Dotted: k = 2.0','sc');
   pause
   ptid = input(' Do you want a hardcopy ? (1=yes,0=no)');
   if ptid == 1
     print
   end   

   subplot
   subplot(221)
   plot(t,x1_ipw2);grid;
   title('x1');  xlabel('Sec');

   subplot(222)
   plot(t,x2_ipw2);grid
   title('x2 (z)');   xlabel('Sec');

   subplot(223)
   plot(t,u_ipw2); grid;
   title('Control (u)'); xlabel('Sec');

   subplot(224)
   text(0.6,0.4,'Impulse Response @ M2','sc');
   text(0.6,0.35,'Sensor Noise: 0.001*sin(100t)','sc')
   text(0.65,0.3,'Dashed: k = 0.5','sc');
   text(0.65,0.25,'Solid:  k = 1.0','sc');
   text(0.65,0.2,'Dotted: k = 2.0','sc');
   pause
   ptid = input(' Do you want a hardcopy ? (1=yes,0=no)');
   if ptid == 1
     print
   end
%
subplot
subplot(221)
semilogx(w,gf);title('Controller F(s)');
xlabel('Rad/Sec'); ylabel('Gain (db)')

subplot(223)
semilogx(w,pf);xlabel('Rad/Sec');ylabel('Phase (deg)')

subplot(222)
semilogx(w,gl); title('Loop TF G*F'); xlabel('Rad/Sec');
text(0.002,-50,['Min. GM: ',num2str(gmin),' db']);
text(0.002,-150,['Max. GM: ',num2str(gmax),' db']);

subplot(224)
semilogx(w,pl);
xlabel('Rad/Sec (k = 0.5(- -), 1(-), 2(.))');ylabel('Phase (deg)')
text(0.002,max(min(pl))+100,['Min. PM: ',num2str(pmin),' deg']);
text(0.002,max(min(pl)),['Max. PM: ',num2str(pmax),' deg']);
pause

ptid = input(' Do you want a hardcopy ? (1=yes,0=no)');
   if ptid == 1
     print
   end
%
clc
disp(' ');
disp(' ');
disp('  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *')
disp('  *                                                         *')
disp('  *      Your design is accomplished ..                     *')
disp('  *              Controller: (af,bf,-cf,-df).               *')
disp('  *                                                         *')
disp('  *       (strike a key to go back to the main maneu)       *')
disp('  *                                                         *')
disp('  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *')
pause
%
% ----------- End of MUPLT.M % RYC/MGS %