home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts / control / sys2ss.m < prev    next >
Text File  |  1999-03-05  |  3KB  |  76 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 [a,b,c,d,tsam,n,nz,stname,inname,outname,yd] = sys2ss(sys)
  18.   # function [a,b,c,d(,tsam,n,nz,stname,inname,outname,yd)] = sys2ss(sys)
  19.   # Convert from system data structure to state space form
  20.   # inputs:
  21.   #    sys: system data structure for the state space system
  22.   #
  23.   #      x' = Ax + Bu
  24.   #      y  = Cx + Du
  25.   #
  26.   #  or a similar discrete-time system.  
  27.   #
  28.   # outputs:
  29.   #    a,b,c,d: state space matrices for sys
  30.   #    tsam: sampling time of sys (0 if continuous)
  31.   #    n, nz: number of continuous, discrete states (discrete states come
  32.   #          last in state vector x)
  33.   #    stname, inname, outname: signal names (strings);  names of states,
  34.   #          inputs, and outputs, respectively
  35.   #    yd: binary vector; yd(ii) is nonzero if output y is discrete.
  36.   # 
  37.   # A warning message is printed if the system is a mixed 
  38.   # continuous/discrete system.
  39.  
  40.   # Written by David Clem August 19, 1994
  41.   # Updates by John Ingram July 14, 1996
  42.  
  43.   if(nargin != 1)
  44.     usage("[a,b,c,d,tsam,n,nz,stname,inname,outname,yd] = sys2ss(sys)")
  45.   endif
  46.  
  47.   if (nargout > 11)
  48.     warning(["sys2ss: ",num2str(nargout)," out arguments exceeds max=11"])
  49.     usage("[a,b,c,d,tsam,n,nz,stname,inname,outname,yd] = sys2ss(sys)")
  50.   endif
  51.  
  52.   if( ! is_struct(sys) )
  53.     error("input argument must be a system data structure");
  54.   endif
  55.  
  56.   sys = sysupdate(sys,"ss");        # make sure state space data is there
  57.   [n,nz,m,p] = sysdimensions(sys);
  58.   [stname,inname,outname,yd] = sysgetsignals(sys);
  59.   tsam = sysgettsam(sys);
  60.  
  61.   cont = sum(yd == 0) + n;
  62.   dig = sum(yd != 0) + nz + tsam;
  63.   if(cont*dig)
  64.     warning("sys2ss: input system is mixed continuous/discrete");
  65.   endif
  66.  
  67.   a = sys.a;
  68.   b = sys.b;
  69.   c = sys.c;
  70.   d = sys.d;
  71.  
  72. endfunction
  73.  
  74.