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

  1. ## Copyright (C) 1996 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{dsys}, @var{Adc}, @var{Cdc}] =} sysdisc (@var{sys})
  21. ## 
  22. ## @strong{Inputs}
  23. ## @var{sys} = system data structure
  24. ## 
  25. ## @strong{Outputs}
  26. ## @table @var
  27. ## @item dsys
  28. ##  purely discrete portion of sys (returned empty if there is
  29. ##           no purely discrete path from inputs to outputs)
  30. ## @item    Adc, Cdc
  31. ##  connections from continuous states to discrete states and discrete
  32. ##     outputs, respectively.
  33. ## @end table
  34. ## 
  35. ## @end deftypefn
  36.  
  37. function [dsys, Adc, Cdc] = sysdisc (sys)
  38.  
  39.   ## function [dsys,Adc,Cdc] = sysdisc(sys)
  40.   ## inputs: sys = system data structure
  41.   ## outputs:
  42.   ##    dsys: purely discrete portion of sys (returned empty if there is
  43.   ##          no purely discrete path from inputs to outputs)
  44.   ##    Adc, Cdc: connections from continuous states to discrete states/discrete
  45.   ##    outputs, respectively.
  46.   ##
  47.  
  48.   save_empty = empty_list_elements_ok;
  49.   empty_list_elements_ok = 1;
  50.  
  51.  
  52.   if (nargin != 1)
  53.     usage("[dsys,Adc,Cdc] = sysdisc(sys)");
  54.   elseif (!is_struct(sys))
  55.     error("sys must be in system data structure form");
  56.   endif
  57.  
  58.   sys = sysupdate(sys,"ss");
  59.   [n_tot,st_c,st_d,y_c,y_d] = syscont_disc(sys);    # get ranges
  60.  
  61.   ## assume there's nothing there; build partitions as appropriate
  62.   Add = Adc = Bdd = Cdd = Cdc = Ddd = [];
  63.   
  64.   if(isempty(st_d) & isempty(y_d))
  65.     error("sysdisc: expecting discrete states and/or continous outputs");
  66.   elseif (isempty(st_d))
  67.     warning("sysdisc: no discrete states");
  68.   elseif(isempty(y_d))
  69.     warning("sysdisc: no discrete outputs");
  70.   endif
  71.  
  72.   [aa,bb,cc,dd] = sys2ss(sys);
  73.   if(!isempty(st_d) )
  74.     Add = aa( st_d , st_d);
  75.     stname = sysgetsignals(sys,"st",st_d);
  76.     Bdd = bb( st_d , :);
  77.     if(!isempty(st_c))
  78.       Adc = aa( st_d , st_c);
  79.     endif
  80.     if(!isempty(y_d))
  81.       Cdd = cc(y_d , st_d);
  82.     endif
  83.   else
  84.     stname = [];
  85.   endif
  86.   if(!isempty(y_d))
  87.     Ddd = dd(y_d , :);
  88.     outname = sysgetsignals(sys,"out",y_d);
  89.     if(!isempty(st_c))
  90.       Cdc = cc(y_d , st_c);
  91.     endif
  92.   else
  93.     outname=[];
  94.   endif
  95.   inname = sysgetsignals(sys,"in");
  96.   outlist = 1:rows(outname);
  97.  
  98.   if(!isempty(outname))
  99.     tsam = sysgettsam(sys);
  100.     [nc,nz] = sysdimensions(sys);
  101.     dsys = ss2sys(Add,Bdd,Cdd,Ddd,tsam,0,nz,stname,inname,outname,outlist);
  102.   else
  103.     dsys=[];
  104.   endif
  105.  
  106.   empty_list_elements_ok = save_empty;
  107.  
  108. endfunction
  109.