home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts / control / sysgroup.m < prev    next >
Text File  |  1999-03-05  |  4KB  |  122 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 = sysgroup(Asys,Bsys)
  18. # function sys = sysgroup(Asys,Bsys)
  19. # Combines two system data structures into a single system
  20. #
  21. # input: Asys, Bsys: system data structures
  22. # output: sys: Asys and Bsys are combined into a single system:
  23. #
  24. #              __________________
  25. #              |    ________    |
  26. #     u1 ----->|--> | Asys |--->|----> y1
  27. #              |    --------    |
  28. #              |    ________    |
  29. #     u2 ----->|--> | Bsys |--->|----> y2
  30. #              |    --------    |
  31. #              ------------------
  32. #                   Ksys
  33. # The function also rearranges the A,B,C matrices so that the 
  34. # continuous states come first and the discrete states come last.
  35. # If there are duplicate names, the second name has a unique suffix appended
  36. # on to the end of the name.
  37.  
  38. # A. S. Hodel August 1995
  39. # modified by John Ingram July 1996
  40.  
  41.   save_val = implicit_str_to_num_ok;    # save for later
  42.   implicit_str_to_num_ok = 1;
  43.  
  44.   save_emp = empty_list_elements_ok;
  45.   empty_list_elements_ok = 1;
  46.  
  47.   if(nargin ~= 2)
  48.     usage("sys = sysgroup(Asys,Bsys)");
  49.   elseif( !is_struct(Asys) | !is_struct(Bsys) )
  50.     error("sysgroup: input arguments must both be structured systems");
  51.   endif
  52.  
  53.   # extract information from Asys, Bsys to consruct sys
  54.   Asys = sysupdate(Asys,"ss");
  55.   Bsys = sysupdate(Bsys,"ss");
  56.   [n1,nz1,m1,p1] = sysdimensions(Asys);
  57.   [n2,nz2,m2,p2] = sysdimensions(Bsys);
  58.   [Aa,Ab,Ac,Ad,Atsam,An,Anz,Ast,Ain,Aout,Ayd] = sys2ss(Asys);
  59.   [Ba,Bb,Bc,Bd,Btsam,Bn,Bnz,Bst,Bin,Bout,Byd] = sys2ss(Bsys);
  60.   nA = An + Anz;
  61.   nB = Bn + Bnz;
  62.  
  63.   if(p1*m1*p2*m2 == 0)
  64.     error("sysgroup: argument lacks inputs and/or outputs");
  65.  
  66.   elseif((Atsam + Btsam > 0) & (Atsam * Btsam == 0) )
  67.     warning("sysgroup: creating combination of continuous and discrete systems")
  68.  
  69.   elseif(Atsam != Btsam)
  70.     error("sysgroup: Asys.tsam=%e, Bsys.tsam =%e", Atsam, Btsam);
  71.   endif
  72.  
  73.   A = [Aa,zeros(nA,nB); zeros(nB,nA),Ba];
  74.   B = [Ab,zeros(nA,m2); zeros(nB,m1),Bb];
  75.   C = [Ac,zeros(p1,nB); zeros(p2,nA),Bc];
  76.   D = [Ad,zeros(p1,m2); zeros(p2,m1),Bd];
  77.   tsam = max(Atsam,Btsam);
  78.  
  79.   # construct combined signal names; stnames must check for pure gain blocks
  80.   if(isempty(Ast))
  81.     stname = Bst;
  82.   elseif(isempty(Bst))
  83.     stname = Ast;
  84.   else
  85.     stname  = append(Ast, Bst);
  86.   endif
  87.   inname  = append(Ain, Bin);
  88.   outname = append(Aout,Bout);
  89.  
  90.   # Sort states into continous first, then discrete
  91.   dstates = ones(1,(nA+nB));
  92.   if(An)
  93.     dstates(1:(An)) = zeros(1,An);
  94.   endif
  95.   if(Bn)
  96.     dstates((nA+1):(nA+Bn)) = zeros(1,Bn);
  97.   endif
  98.   [tmp,pv] = sort(dstates);
  99.   A = A(pv,pv);
  100.   B = B(pv,:);
  101.   C = C(:,pv);
  102.   stname = stname(pv);
  103.  
  104.   # check for duplicate signal names
  105.   inname = sysgroupn(inname,"input");
  106.   stname = sysgroupn(stname,"state");
  107.   outname = sysgroupn(outname,"output");
  108.  
  109.   # mark discrete outputs
  110.   outlist = find([Ayd, Byd]);
  111.  
  112.   # build new system
  113.   sys = ss2sys(A,B,C,D,tsam,An+Bn,Anz+Bnz,stname,inname,outname);
  114.  
  115.   implicit_str_to_num_ok = save_val;    # restore value  
  116.   empty_list_elements_ok = save_emp;
  117.  
  118. endfunction
  119.