% Generates Fig 3.19
% 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

clear all; close all;

block319;

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


lw=2;
Ms=20;
%
a1=0.02;
a=[-1 0 0; 0 -2*a1 -a1*a1-pi*pi; 0 1 0];
b=[1; 1; 0];
c=[1 0 pi];
d=0;
[t,x,y]=sim('block319',[0, 40]);
h=2;
[ph,ga]=c2d(a,b,h);
[y2,x]=dstep(ph,ga,c,d,1,51);
t2=h*[0:50]';
subplot(2,1,1);
hpl=plot(t2,y2,'m.',t,y(:,1),'k','Linew',lw);
%title('Fig 3.19');
set(hpl,'MarkerSize',Ms)
%set(gca,'xtick',[0:2:20 20:2:40],'ytick',[0 1 2]);
set(gca,'Fontsize',9,'Fontname','NewCenturySchlbk');
ylabel('Output','Fontname','NewCenturySchlbk','Fontsize',9)
%xlabel('Time','Fontname','NewCenturySchlbk','Fontsize',9)
axis([0,40,0,2]);
text(-4,2,'(a)','Fontname','NewCenturySchlbk','Fontsize',9)
title(' h = 2' );
grid;
drawnow;
pause;

h=1.8;
[ph,ga]=c2d(a,b,h);
[y2,x]=dstep(ph,ga,c,d,1,51);
t2=h*[0:50]';
subplot(2,1,2);
hpl=plot(t2,y2,'m.',t,y(:,1),'k','Linew',lw);
%title('Fig 3.19');
set(hpl,'MarkerSize',Ms)
%set(gca,'xtick',[0 20 40],'ytick',[0 1 2]);
set(gca,'Fontsize',9,'Fontname','NewCenturySchlbk');
ylabel('Output','Fontname','NewCenturySchlbk','Fontsize',9)
xlabel('Time','Fontname','NewCenturySchlbk','Fontsize',9)
axis([0,40,0,2]);
text(-4,2,'(b)','Fontname','NewCenturySchlbk','Fontsize',9)
title(' h = 1.8' );
grid;
drawnow;
