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

  1. # Copyright (C) 1996 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] = sysmult(Asys,Bsys)
  18. #
  19. # [sys] = sysmult(Asys,Bsys)
  20. #
  21. # returns sys = Asys*Bsys
  22. #
  23. # This function takes two systems, Asys and Bsys, and multiplies them together.
  24. # This has the effect of connecting the outputs of Bsys to the inputs of Asys.
  25. #
  26. #
  27. #     u   ----------     ----------
  28. #     --->|  Bsys  |---->|  Asys  |--->
  29. #         ----------     ----------
  30. #
  31. # A warning occurs if there is direct feed-through
  32. # from an input of Bsys or a continuous state of Bsys through a discrete 
  33. # output of Bsys to a continuous state or output in Asys (system data structure form 
  34. # does not recognize discrete inputs)
  35.  
  36. # Written by John Ingram July 1996
  37.  
  38.   save_val = implicit_str_to_num_ok;    # save for later
  39.   implicit_str_to_num_ok = 1;
  40.  
  41.   if(nargin != 2)
  42.     usage("sysmult:  [sys] = sysmult(Asys,Bsys)");
  43.   endif
  44.  
  45.   # check inputs
  46.   if(!is_struct(Asys) | !is_struct(Bsys))
  47.     error("Both Asys and Bsys must be in system data structure form")
  48.   endif
  49.  
  50.   # check for compatibility
  51.   [An,Anz,Am,Ap] = sysdimensions(Asys);
  52.   [Bn,Bnz,Bm,Bp] = sysdimensions(Bsys);
  53.   if(Bp != Am)
  54.     error(["Bsys has ",num2str(Bp)," outputs, Asys has ",num2str(Am), ...
  55.     " inputs; mismatch."]);
  56.   endif
  57.  
  58.   [Aa,Ab,Ac,Ad,Atsam,An,Anz,Astname,Ainname,Aoutname,Ayd] = sys2ss(Asys);
  59.   [Ba,Bb,Bc,Bd,Btsam,Bn,Bnz,Bstname,Binname,Boutname,Byd] = sys2ss(Bsys);
  60.  
  61.   if(Byd)
  62.     # check direct feed-through of inputs through discrete outputs
  63.     alist = find(Byd);
  64.     if(An)
  65.       bd = Ab(1:An)* Bd(alist,:);    
  66.       if(norm(bd,1))
  67.         warning("sysmult: inputs -> Bsys discrete outputs -> continous states of Asys");
  68.       endif
  69.     endif
  70.     # check direct feed-through of continuous state through discrete outputs
  71.     if(Bn)
  72.       bc = Ab(1:An)* Bc(alist,1:(Bn));    
  73.       if( norm(bc,1) )
  74.         warning("sysmult: Bsys states -> Bsys discrete outputs -> continuous states of Asys");
  75.       endif
  76.     endif
  77.   endif
  78.  
  79.   # change signal names to avoid spurious warnings from sysgroup
  80.   Asys = syssetsignals(Asys,"in",sysdefioname(Am,"A_sysmult_tmp_name"));
  81.   Bsys = syssetsignals(Bsys,"out",sysdefioname(Bp,"B_sysmult_tmp_name"));
  82.  
  83.   sys = sysgroup(Asys,Bsys);
  84.  
  85.   # connect outputs of B to inputs of A
  86.   sys = sysconnect(sys,Ap+(1:Bp),1:Am);
  87.  
  88.   # now keep only  outputs of A and inputs of B
  89.   sys = sysprune(sys,1:Ap,Am+(1:Bm));
  90.  
  91.   implicit_str_to_num_ok = save_val;    # restore value  
  92. endfunction  
  93.   
  94.