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

  1. ## Copyright (C) 1996,1999 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} =} sysmult( @var{Asys}, @var{Bsys})
  21. ## Compute @math{sys = Asys*Bsys} (series connection):
  22. ## @example
  23. ## @group
  24. ## u   ----------     ----------
  25. ## --->|  Bsys  |---->|  Asys  |--->
  26. ##     ----------     ----------
  27. ## @end group
  28. ## @end example
  29. ## A warning occurs if there is direct feed-through
  30. ## from an input of Bsys or a continuous state of Bsys through a discrete 
  31. ## output of Bsys to a continuous state or output in Asys (system data structure
  32. ## does not recognize discrete inputs).
  33. ## @end deftypefn
  34.  
  35. function sys = sysmult (...)
  36.  
  37.   ## Written by John Ingram July 1996
  38.   ## updated for variable number of arguments by A. S. Hodel July 1999
  39.  
  40.   if(nargin < 1)
  41.     usage("sysmult: sys = sysmult(Asys{,Bsys,...})");
  42.   endif
  43.  
  44.   ## collect all arguments
  45.   arglist = list();
  46.   va_start();
  47.   for kk=1:nargin
  48.     arglist(kk) = va_arg();
  49.     if(!is_struct(nth(arglist,kk)))
  50.       error("sysadd: argument %d is not a data structure",kk);
  51.     endif
  52.   endfor
  53.  
  54.   ## check system dimensions
  55.   [n,nz,mg,pg,Gyd] = sysdimensions(nth(arglist,1));
  56.   for kk=2:nargin
  57.     [n,nz,mh,ph,Hyd] = sysdimensions(nth(arglist,kk));
  58.     if(mh != pg)
  59.       error("arg %d has %d outputs; arg %d has vs %d inputs",kk,ph,kk-1,mg);
  60.     endif
  61.     [n,nz,mg,pg,Gyd] = sysdimensions(nth(arglist,kk));   # for next iteration
  62.   endfor
  63.  
  64.   ## perform the multiply
  65.   if(nargin == 2)
  66.     Asys = nth(arglist,1);   Bsys = nth(arglist,2);
  67.  
  68.     [An,Anz,Am,Ap] = sysdimensions(Asys);
  69.     [Bn,Bnz,Bm,Bp] = sysdimensions(Bsys);
  70.  
  71.     [Aa,Ab,Ac,Ad,Atsam,An,Anz,Astname,Ainname,Aoutname,Ayd] = sys2ss(Asys);
  72.     [Ba,Bb,Bc,Bd,Btsam,Bn,Bnz,Bstname,Binname,Boutname,Byd] = sys2ss(Bsys);
  73.   
  74.     if(Byd)
  75.       ## check direct feed-through of inputs through discrete outputs
  76.       alist = find(Byd);
  77.       if(An)
  78.         bd = Ab(1:An)* Bd(alist,:);    
  79.         if(norm(bd,1))
  80.           warning("sysmult: inputs -> Bsys discrete outputs -> continous states of Asys");
  81.         endif
  82.       endif
  83.       ## check direct feed-through of continuous state through discrete outputs
  84.       if(Bn)
  85.         bc = Ab(1:An)* Bc(alist,1:(Bn));    
  86.         if( norm(bc,1) )
  87.           warning("sysmult: Bsys states -> Bsys discrete outputs -> continuous states of Asys");
  88.         endif
  89.       endif
  90.     endif
  91.   
  92.     ## change signal names to avoid spurious warnings from sysgroup
  93.     Asys = syssetsignals(Asys,"in",sysdefioname(Am,"A_sysmult_tmp_name"));
  94.     Bsys = syssetsignals(Bsys,"out",sysdefioname(Bp,"B_sysmult_tmp_name"));
  95.   
  96.     sys = sysgroup(Asys,Bsys);
  97.   
  98.     ## connect outputs of B to inputs of A
  99.     sys = sysconnect(sys,Ap+(1:Bp),1:Am);
  100.    
  101.     ## now keep only  outputs of A and inputs of B
  102.     sys = sysprune(sys,1:Ap,Am+(1:Bm));
  103.  
  104.   else
  105.     ## multiple systems (or a single system); combine together one by one
  106.     sys = nth(arglist,1);
  107.     for kk=2:length(arglist)
  108.       sys = sysmult(sys,nth(arglist,kk));
  109.     endfor
  110.   endif
  111.  
  112. endfunction  
  113.   
  114.