home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fb.zip / octave / SCRIPTS.ZIP / scripts.fat / control / sysdup.m < prev    next >
Text File  |  1999-12-24  |  4KB  |  120 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{retsys} =} sysdup (@var{Asys}, @var{out_idx}, @var{in_idx})
  21. ##  Duplicate specified input/output connections of a system
  22. ## 
  23. ## @strong{Inputs}
  24. ## @table @var
  25. ## @item Asys
  26. ##  system data structure (@xref{ss2sys})
  27. ## @item out_idx,in_idx
  28. ##  list of connections indices; 
  29. ##        duplicates are made of @var{y(out_idx(ii))} and @var{u(in_idx(ii))}.
  30. ## @end table
  31. ## 
  32. ## @strong{Outputs}
  33. ## @var{retsys}: resulting closed loop system:
  34. ##     duplicated i/o names are appended with a @code{"+"} suffix.
  35. ## 
  36. ## 
  37. ## @strong{Method}
  38. ## @code{sysdup} creates copies of selected inputs and outputs as
  39. ##  shown below.  u1/y1 is the set of original inputs/outputs, and 
  40. ##  u2,y2 is the set of duplicated inputs/outputs in the order specified
  41. ##  in @var{in_idx}, @var{out_idx}, respectively
  42. ## @example
  43. ## @group
  44. ##           ____________________
  45. ## u1  ----->|                  |----> y1
  46. ##           |       Asys       |
  47. ## u2 ------>|                  |----->y2 
  48. ## (in_idx)  -------------------| (out_idx)
  49. ## @end group
  50. ## @end example
  51. ## 
  52. ## @end deftypefn
  53.  
  54. function retsys = sysdup (Asys, output_list, input_list)
  55.  
  56.   ## A. S. Hodel August 1995
  57.   ## modified by John Ingram July 1996
  58.  
  59.   if( nargin != 3)
  60.     usage("retsys = sysdup(Asys,output_list,input_list)");
  61.   endif
  62.  
  63.   if( !is_struct(Asys))
  64.     error("Asys must be a system data structure (see ss2sys, tf2sys, or zp2sys)")
  65.   endif
  66.  
  67.   Asys = sysupdat(Asys,"ss");
  68.   [nn,nz,mm,pp] = sysdimen(Asys);
  69.   [aa,bb,cc,dd] = sys2ss(Asys);
  70.  
  71.   ## first duplicate inputs
  72.   if(is_vec(input_list))
  73.     for ii=1:length(input_list);
  74.       bb(:,mm+ii) = bb(:,input_list(ii));
  75.       dd(:,mm+ii) = dd(:,input_list(ii));
  76.     end
  77.   elseif(!isempty(input_list))
  78.     error("input_list must be a vector or empty");
  79.   endif
  80.  
  81.  
  82.   ## now duplicate outputs
  83.   osize = min(size(output_list));
  84.   if(osize == 1)
  85.     for ii=1:length(output_list);
  86.       cc(pp+ii,:) = cc(output_list(ii),:);
  87.       dd(pp+ii,:) = dd(output_list(ii),:);
  88.     end
  89.   elseif(osize != 0)
  90.     error("output_list must be a vector or empty");
  91.   endif
  92.   
  93.   [stnam,innam,outnam,yd] = sysgetsg(Asys);
  94.   tsam = sysgetts(Asys);
  95.  
  96.   ## pack system and then rename signals
  97.   retsys = ss2sys(aa,bb,cc,dd,tsam,nn,nz);
  98.   retsys = syssetsg(retsys,"in",innam,1:mm);
  99.   retsys = syssetsg(retsys,"out",outnam,1:pp);
  100.   retsys = syssetsg(retsys,"yd",yd,1:pp);
  101.  
  102.   ## update added input names
  103.   for ii=(mm+1):(mm+length(input_list))
  104.     onum = input_list(ii-mm);
  105.     strval = sprintf("%s(dup)",sysgetsg(retsys,"in",onum,1) );
  106.     retsys = syssetsg(retsys,"in",strval,ii);
  107.   endfor
  108.  
  109.   ## update added output names/discrete flags
  110.   ## give default names to the added outputs
  111.   for jj=(pp+1):(pp+length(output_list))
  112.     onum = output_list(jj-pp);
  113.     strval = sprintf("%s(dup)",sysgetsg(retsys,"out",onum,1) );
  114.     retsys = syssetsg(retsys,"out",strval,jj);
  115.     dflg = sysgetsg(retsys,"yd",onum);
  116.     retsys = syssetsg(retsys,"yd",dflg,jj);
  117.   endfor
  118.  
  119. endfunction
  120.