home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fb.zip / octave / SCRIPTS.ZIP / scripts / control / sysscale.m < prev    next >
Encoding:
Text File  |  1999-12-15  |  4.6 KB  |  139 lines

  1. ## Copyright (C) 1996,1998 Auburn University.  All Rights Reserved
  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. ## 
  10. ## Octave is distributed in the hope that it will be useful, but WITHOUT 
  11. ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
  12. ## FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License 
  13. ## for more details.
  14. ## 
  15. ## You should have received a copy of the GNU General Public License 
  16. ## along with Octave; see the file COPYING.  If not, write to the Free 
  17. ## Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. 
  18.  
  19. ## -*- texinfo -*-
  20. ## @deftypefn {Function File } {@var{sys} =} sysscale (@var{sys}, @var{outscale}, @var{inscale}@{, @var{outname}, @var{inname}@})
  21. ## scale inputs/outputs of a system.
  22. ## 
  23. ## @strong{Inputs}
  24. ##    sys: structured system
  25. ##    outscale, inscale: constant matrices of appropriate dimension
  26. ## 
  27. ## @strong{Outputs}
  28. ## @var{sys}: resulting open loop system:
  29. ## @example
  30. ##       -----------    -------    -----------
  31. ## u --->| inscale |--->| sys |--->| outscale |---> y
  32. ##       -----------    -------    -----------
  33. ## @end example
  34. ##  If the input names and output names (each a list of strings)
  35. ## are not given and the scaling matrices
  36. ##  are not square, then default names will be given to the inputs and/or
  37. ##  outputs.
  38. ## 
  39. ## A warning message is printed if outscale attempts to add continuous
  40. ## system outputs to discrete system outputs; otherwise @var{yd} is 
  41. ## set appropriately in the returned value of @var{sys}.
  42. ## @end deftypefn
  43.  
  44. function sys = sysscale (sys, outscale, inscale, outname, inname)
  45.  
  46.   ## A. S. Hodel August 1995
  47.   ## modified by John Ingram 7-15-96
  48.  
  49.   if( (nargin < 3) || (nargin > 5)  )
  50.     usage("retsys = sysscale(Asys,output_list,input_list{,inname,outname})");
  51.   elseif (!is_struct(sys))
  52.     error("sys must be a structured system");
  53.   endif
  54.  
  55.   [nn,nz,mm,pp] = sysdimensions(sys);
  56.  
  57.   ## check for omitted scales
  58.   if(isempty(outscale))    outscale = eye(pp);     endif 
  59.   if(isempty(inscale))     inscale = eye(mm);      endif 
  60.  
  61.   ## check dimensions of scaling matrices
  62.   if(mm!=rows(inscale))
  63.     error("inscale(%dx%d) should have %d rows(# system inputs)", ...
  64.       rows(inscale),columns(inscale),mm);
  65.   elseif( pp != columns(outscale) )
  66.     error("outscale(%dx%d) should have %d columns(# system outputs)", ...
  67.       rows(outscale), columns(outscale),pp);
  68.   endif
  69.  
  70.   sysyd = sysgetsignals(sys,"yd");
  71.   outc = find(sysyd==0);
  72.   outd = find(sysyd==1);
  73.  
  74.   if(length(outc) & length(outd))
  75.     for ii = 1:rows(outscale)
  76.       nci = norm(outscale(ii,outc));
  77.       ndi = norm(outscale(ii,outd));
  78.  
  79.       if( nci & ndi)
  80.         warning("sysscale: outscale(%d,:) sums continuous and discrete outputs; setting output to cont",ii)
  81.         sysyd(ii) = 0;
  82.       else
  83.         sysyd(ii) = (ndi != 0);
  84.       endif
  85.     endfor
  86.   else
  87.     sysyd = ones(1,rows(outscale))*( length(outd) > 0);
  88.   endif
  89.  
  90.   ## check for SISO system type
  91.   if strcmp(sysgettype(sys),"tf")
  92.     [num,den,tsam,innam,outnam] = sys2tf(sys);
  93.     num = num*inscale*outscale;
  94.     sys = tf2sys(num,den,tsam,innam,outnam,find(sysyd));
  95.     return
  96.   elseif strcmp(sysgettype(sys),"zp")
  97.     [zer,pol,kk,tsam,innam,outnam] = sys2zp(sys);
  98.     kk = kk*inscale*outscale;
  99.     sys = zp2sys(zer,pol,k,tsam,innam,outnam,find(sysyd));
  100.     return
  101.   endif
  102.  
  103.   ## it's a state space system...
  104.  
  105.   [sysa,sysb,sysc,sysd,systsam, ...
  106.     sysn,sysnz,sysstname,sysinname,sysoutname,oldyd] = sys2ss(sys);
  107.  
  108.   sysb = sysb*inscale;
  109.   sysc = outscale*sysc;
  110.   sysd = outscale*sysd*inscale;
  111.  
  112.   if( !is_square(outscale) )
  113.     ## strip extra output names (if any)
  114.     sysoutname = sysoutname(1:min(rows(outscale),columns(outscale)));
  115.     if( nargin < 4)
  116.       warning("sysscale: outscale not square, outname not specified");
  117.       warning("sysscale:  using default output names");
  118.       outname = sysdefioname(rows(sysc),"y");
  119.     endif
  120.   else
  121.     outname = sysoutname;
  122.   endif
  123.   if( !is_square(inscale) )
  124.     ## strip extra output names (if any)
  125.     sysinname = sysinname(1:min(rows(inscale),columns(inscale)));
  126.     if(nargin < 5)
  127.       warning("sysscale: inscale not square, inname not specified");
  128.       warning("sysscale:  using default input names");
  129.       inname = sysdefioname(columns(sysb),"u");
  130.     endif
  131.   else
  132.     inname = sysgetsignals(sys,"in");
  133.   endif
  134.  
  135.   sys = ss2sys(sysa,sysb,sysc,sysd,systsam,nn,nz,sysstname, ...
  136.     inname,outname,find(sysyd==1));
  137.  
  138. endfunction
  139.