home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts / control / tzero.m < prev    next >
Text File  |  1999-03-05  |  3KB  |  114 lines

  1. # Copyright (C) 1996 A. Scottedward Hodel 
  2. #
  3. # This file is part of Octave. 
  4. #
  5. # Octave is free software; you can redistribute it and/or modify it 
  6. # under the terms of the GNU General Public License as published by the 
  7. # Free Software Foundation; either version 2, or (at your option) any 
  8. # later version. 
  9. # Octave is distributed in the hope that it will be useful, but WITHOUT 
  10. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
  11. # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License 
  12. # for more details.
  13. # You should have received a copy of the GNU General Public License 
  14. # along with Octave; see the file COPYING.  If not, write to the Free 
  15. # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  16.  
  17. function [zer, gain] = tzero(A,B,C,D)
  18.   # [zer{,gain}] = tzero(A,B,C,D) -or-
  19.   # [zer{,gain}] = tzero(Asys)
  20.   # Compute transmission zeros of a continuous
  21.   #      .
  22.   #      x = Ax + Bu
  23.   #      y = Cx + Du
  24.   #
  25.   # or discrete
  26.   #      x(k+1) = A x(k) + B u(k)
  27.   #      y(k)   = C x(k) + D u(k)
  28.   #
  29.   # system.
  30.   #
  31.   # outputs: 
  32.   #   zer: transmission zeros of the system
  33.   #   gain: leading coefficient (pole-zero form) of SISO transfer function
  34.   #         returns gain=0 if system is multivariable
  35.   # References:
  36.   # Hodel, "Computation of Zeros with Balancing," 1992 Lin. Alg. Appl.
  37.   
  38.   # R. Bruce Tenison July 4, 1994
  39.   # A. S. Hodel Aug 1995: allow for MIMO and system data structures
  40.  
  41.   # get A,B,C,D and Asys variables, regardless of initial form
  42.   if(nargin == 4)
  43.     Asys = ss2sys(A,B,C,D);
  44.   elseif( (nargin == 1) && (! is_struct(A)))
  45.     usage("[zer,gain] = tzero(A,B,C,D) or zer = tzero(Asys)");
  46.   elseif(nargin != 1)
  47.     usage("[zer,gain] = tzero(A,B,C,D) or zer = tzero(Asys)");
  48.   else
  49.     Asys = A;
  50.     [A,B,C,D] = sys2ss(Asys);
  51.   endif
  52.  
  53.   Ao = Asys;            # save for leading coefficient
  54.   siso = is_siso(Asys);
  55.   digital = is_digital(Asys);    # check if it's mixed or not
  56.  
  57.   # see if it's a gain block
  58.   if(isempty(A))
  59.     zer = [];
  60.     gain = D;
  61.     return;
  62.   endif
  63.  
  64.   # First, balance the system via the zero computation generalized eigenvalue
  65.   # problem balancing method (Hodel and Tiller, Linear Alg. Appl., 1992)
  66.  
  67.   Asys = zgpbal(Asys); [A,B,C,D] = sys2ss(Asys);   # balance coefficients
  68.   meps = 2*eps*norm([A, B; C, D],'fro');
  69.   Asys = zgreduce(Asys,meps);  [A, B, C, D] = sys2ss(Asys); # ENVD algorithm
  70.   if(!isempty(A))
  71.     # repeat with dual system
  72.     Asys = ss2sys(A', C', B', D');   Asys = zgreduce(Asys,meps);
  73.  
  74.     # transform back
  75.     [A,B,C,D] = sys2ss(Asys);    Asys = ss2sys(A', C', B', D');
  76.   endif
  77.  
  78.   zer = [];            # assume none
  79.   [A,B,C,D] = sys2ss(Asys);
  80.   if( !isempty(C) )
  81.     [W,r,Pi] = qr([C, D]');
  82.     [nonz,ztmp] = zgrownorm(r,meps);
  83.     if(nonz)
  84.       # We can now solve the generalized eigenvalue problem.
  85.       [pp,mm] = size(D);
  86.       nn = rows(A);
  87.       Afm = [A , B ; C, D] * W';
  88.       Bfm = [eye(nn), zeros(nn,mm); zeros(pp,nn+mm)]*W';
  89.  
  90.       jdx = (mm+1):(mm+nn);
  91.       Af = Afm(1:nn,jdx);
  92.       Bf = Bfm(1:nn,jdx);
  93.       zer = qz(Af,Bf);
  94.     endif
  95.   endif
  96.   
  97.   mz = length(zer);
  98.   [A,B,C,D] = sys2ss(Ao);        # recover original system
  99.   #compute leading coefficient
  100.   if ( (nargout == 2) && siso)
  101.     n = rows(A);
  102.     if ( mz == n)
  103.       gain = D;
  104.     elseif ( mz < n )
  105.       gain = C*(A^(n-1-mz))*B;
  106.     endif
  107.   else
  108.     gain = [];
  109.   endif
  110. endfunction
  111.  
  112.