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