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

  1. # Copyright (C) 1996,1998 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 sys = sysscale(sys,outscale,inscale,outname,inname)
  18. #
  19. # function sys = sysscale(sys,outscale,inscale[,outname,inname])
  20. # scale inputs/outputs of a system.
  21. #
  22. # inputs:
  23. #   sys: system data structure
  24. #   outscale, inscale: constant matrices of appropriate dimension
  25. # output: sys: resulting open loop system:
  26. #
  27. #           -----------    -------    -----------
  28. #     u --->| inscale |--->| sys |--->| outscale |---> y
  29. #           -----------    -------    -----------
  30. # If the input names and output names are not given and the scaling matrices
  31. # are not square, then default names will be given to the inputs and/or
  32. # outputs.
  33. #
  34. # A warning message is printed if outscale attempts to add continuous
  35. # system outputs to discrete system outputs; otherwise yd is set appropriately
  36.  
  37. # A. S. Hodel August 1995
  38. # modified by John Ingram 7-15-96
  39.  
  40.   if( (nargin < 3) || (nargin > 5)  )
  41.     usage("retsys = sysscale(Asys,output_list,input_list{,inname,outname})");
  42.   elseif (!is_struct(sys))
  43.     error("sys must be a structured system");
  44.   endif
  45.  
  46.   [nn,nz,mm,pp] = sysdimensions(sys);
  47.  
  48.   # check for omitted scales
  49.   if(isempty(outscale))    outscale = eye(pp);     endif 
  50.   if(isempty(inscale))     inscale = eye(mm);      endif 
  51.  
  52.   # check dimensions of scaling matrices
  53.   if(mm!=rows(inscale))
  54.     error("inscale(%dx%d) should have %d rows(# system inputs)", ...
  55.       rows(inscale),columns(inscale),mm);
  56.   elseif( pp != columns(outscale) )
  57.     error("outscale(%dx%d) should have %d columns(# system outputs)", ...
  58.       rows(outscale), columns(outscale),pp);
  59.   endif
  60.  
  61.   sysyd = sysgetsignals(sys,"yd");
  62.   outc = find(sysyd==0);
  63.   outd = find(sysyd==1);
  64.  
  65.   if(length(outc) & length(outd))
  66.     for ii = 1:rows(outscale)
  67.       nci = norm(outscale(ii,outc));
  68.       ndi = norm(outscale(ii,outd));
  69.  
  70.       if( nci & ndi)
  71.         warning("sysscale: outscale(%d,:) sums continuous and discrete outputs; setting output to cont",ii)
  72.         sysyd(ii) = 0;
  73.       else
  74.         sysyd(ii) = (ndi != 0);
  75.       endif
  76.     endfor
  77.   else
  78.     sysyd = ones(1,rows(outscale))*( length(outd) > 0);
  79.   endif
  80.  
  81.   # check for SISO system type
  82.   if strcmp(sysgettype(sys),"tf")
  83.     [num,den,tsam,innam,outnam] = sys2tf(sys);
  84.     num = num*inscale*outscale;
  85.     sys = tf2sys(num,den,tsam,innam,outnam,find(sysyd));
  86.     return
  87.   elseif strcmp(sysgettype(sys),"zp")
  88.     [zer,pol,kk,tsam,innam,outnam] = sys2zp(sys);
  89.     kk = kk*inscale*outscale;
  90.     sys = zp2sys(zer,pol,k,tsam,innam,outnam,find(sysyd));
  91.     return
  92.   endif
  93.  
  94.   # it's a state space system...
  95.  
  96.   [sysa,sysb,sysc,sysd,systsam, ...
  97.     sysn,sysnz,sysstname,sysinname,sysoutname,oldyd] = sys2ss(sys);
  98.  
  99.   sysb = sysb*inscale;
  100.   sysc = outscale*sysc;
  101.   sysd = outscale*sysd*inscale;
  102.  
  103.   if( !is_square(outscale) )
  104.     # strip extra output names (if any)
  105.     sysoutname = sysoutname(1:min(rows(outscale),columns(outscale)));
  106.     if( nargin < 4)
  107.       warning("sysscale: outscale not square, outname not specified");
  108.       warning("sysscale:  using default output names");
  109.       outname = sysdefioname(rows(sysc),"y");
  110.     endif
  111.   else
  112.     outname = sysoutname;
  113.   endif
  114.   if( !is_square(inscale) )
  115.     # strip extra output names (if any)
  116.     sysinname = sysinname(1:min(rows(inscale),columns(inscale)));
  117.     if(nargin < 5)
  118.       warning("sysscale: inscale not square, inname not specified");
  119.       warning("sysscale:  using default input names");
  120.       inname = sysdefioname(columns(sysb),"u");
  121.     endif
  122.   else
  123.     inname = sysgetsignals(sys,"in");
  124.   endif
  125.  
  126.   sys = ss2sys(sysa,sysb,sysc,sysd,systsam,nn,nz,sysstname, ...
  127.     inname,outname,find(sysyd==1));
  128.  
  129. endfunction
  130.