function sysr = minreal(sys,tol)
%MINREAL  Minimal realization and pole-zero cancellation.
%
%   SYSr = MINREAL(SYS)
%
%   For state-space LTI systems SYS, this produces a minimal 
%   realization SYSr of SYS.  For transfer function or 
%   zero/pole/gain models, SYSr is a simplified model where 
%   all common poles and zeros have been cancelled.
%
%   SYSr = MINREAL(SYS,TOL)  further specifies the tolerance 
%   used for state elimination or pole-zero cancellations.  
%   The default value is SQRT(EPS) and increasing this tolerance
%   forces additional state deletions or pole/zero cancellations.
%
%   See also  BALREAL, MODRED.

%   J.N. Little 7-17-86
%   Revised A.C.W.Grace 12-1-89, P. Gahinet 8-28-96
%   Copyright (c) 1986-97 by The MathWorks, Inc.
%   $Revision: 1.2 $  $Date: 1997/04/09 00:28:21 $

ni = nargin;
error(nargchk(1,2,ni))
if ni==1,
   tol = sqrt(eps);
end

sysr = tf(minreal(zpk(sys),tol));
