% Generates Fig 4.2
% Computer Controlled Systems (3rd ed)
% Author: B. Wittenmark
% Last edit: 1997-06-30
% Copyright (c) 1996 by K. J. Åström, B. Wittenmark and
% Department of Automatic Control, Lund Institute of
% Technology, Lund, Sweden

close all; clear all;

newplot;
set(gcf,'PaperUnits','centimeters','PaperPosition',[2 2 13 10])
set(gcf,'Units','centimeters','position',get(gcf,'PaperPosition'))

lw=2;
m=0;
t0=0;
x10=1;
x20=1;
zeta=0.707;
om=0.5;
h=0.88;
clf;
%
p1=-2*exp(-zeta*om*h)*cos(om*h*sqrt(1-zeta*zeta));
p2=exp(-2*zeta*om*h);
l1=(1+p1+p2)/(h*h);
l2=(3+p1-p2)/(2*h);
[t,x,y]=sim('block402',[0, 15]);
subplot(2,2,1);
plot(t,y(:,1),'k:','Linew',lw);
axis([0,15,-0.5,2.5]);
%title(['Fig 4.2']);
set(gca,'Fontsize',9,'Fontname','NewCenturySchlbk');
set(gca,'xtick',[0 5 10 15],'ytick',[0 1 2]);
ylabel('Output','Fontsize',9,'Fontname','NewCenturySchlbk')
text(-3.5,2.4,'(a)','fontname','NewCenturySchlbk','fontsize',9)
title('w h = 0.44; \zeta = 0.707; x(0)=[1;1]');
hold on
drawnow;
%
subplot(2,2,2);
[ts,ys]=stairs(t,y(:,3));
plot(ts,ys,'k-','Linew',lw);
axis([0,15,-6,3]);
%title(['omega=0.5']);
set(gca,'Fontsize',9,'Fontname','NewCenturySchlbk');
set(gca,'xtick',[0 5 10 15],'ytick',[-5 0]);
ylabel('Input','Fontsize',9,'Fontname','NewCenturySchlbk')
text(-3.5,2.7,'(b)','fontname','NewCenturySchlbk','fontsize',9)
title('w = 0.5; h = 0.88');
drawnow;
pause;
%
h=0.44;
om=1;
p1=-2*exp(-zeta*om*h)*cos(om*h*sqrt(1-zeta*zeta));
p2=exp(-2*zeta*om*h);
l1=(1+p1+p2)/(h*h);
l2=(3+p1-p2)/(2*h);
[t,x,y]=sim('block402',[0, 15]);
subplot(2,2,1);
plot(t,y(:,1),'r--','Linew',lw);
axis([0,15,-0.5,2.5]);
drawnow;
%
subplot(2,2,3);
[ts,ys]=stairs(t,y(:,3));
plot(ts,ys,'r-','Linew',lw);
axis([0,15,-6,3]);
%title(['omega=1']);
set(gca,'Fontsize',9,'Fontname','NewCenturySchlbk');
set(gca,'xtick',[0 5 10 15],'ytick',[-5 0]);
xlabel('Time','Fontsize',9,'Fontname','NewCenturySchlbk')
ylabel('Input','Fontsize',9,'Fontname','NewCenturySchlbk')
text(-3.5,2.7,'(c)','fontname','NewCenturySchlbk','fontsize',9)
title('w = 1; h = 0.44');
drawnow;
pause;
%
h=0.22;
om=2;
p1=-2*exp(-zeta*om*h)*cos(om*h*sqrt(1-zeta*zeta));
p2=exp(-2*zeta*om*h);
l1=(1+p1+p2)/(h*h);
l2=(3+p1-p2)/(2*h);
[t,x,y]=sim('block402',[0, 15]);
subplot(2,2,1);
plot(t,y(:,1),'b-','Linew',lw);
axis([0,15,-0.5,2.5]);
drawnow;
hold off
%
subplot(2,2,4);
[ts,ys]=stairs(t,y(:,3));
plot(ts,ys,'b-','Linew',lw);
axis([0,15,-6,3]);
%title(['omega=2']);
set(gca,'Fontsize',9,'Fontname','NewCenturySchlbk');
set(gca,'xtick',[0 5 10 15],'ytick',[-5 0]);
xlabel('Time','Fontsize',9,'Fontname','NewCenturySchlbk')
ylabel('Input','Fontsize',9,'Fontname','NewCenturySchlbk')
text(-3.5,2.7,'(d)','fontname','NewCenturySchlbk','fontsize',9)
title('w = 2; h = 0.22');
ylblalgn;
drawnow;
%
