% ejemplo 10.4, Aström_Adaptive Control, pag. 440
% "Second-order VSS"
% elaboro E.Quintero.M 7jul'99
%-------------------------------------------------
clear
% parametros
time=0; tf=10; xx=[];
dt=0.01;    % integration step size
mu=0.5; yr=0; eps=0.01;
A=[1 0;1 0]; B=[1;0];
u=0; x=[1.5 0]';
while(time<(tf-dt))
%--------------------------------------------------------
%     control signal computation
      sigma=x(1)+x(2);
      if(abs(sigma)<=eps)
         sat=sigma/eps;
      else
         sat=sign(sigma);
      end
      u=-[2 0]*x-mu*sat;
      dx=A*x+B*u;
      y=x(2);
      xx=[xx; time x' u];
%--------------------------------------------------------
      x=x+dx*dt;
      time=time+dt;
end
format short e
figure
subplot(2,1,1),plot(xx(:,1),xx(:,2),xx(:,1),xx(:,3)),grid
subplot(2,1,2),plot(xx(:,1),xx(:,4)),grid
figure
subplot(1,1,1),plot(xx(:,2),xx(:,3)),grid
