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

  1. ## Copyright (C) 1996, 1998 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{a},@var{b},@var{c},@var{d},@var{tsam},@var{n},@var{nz},@var{stname},@var{inname},@var{outname},@var{yd}] =} sys2ss (@var{sys})
  21. ## Extract state space representation from system data structure.  
  22. ## 
  23. ## @strong{Inputs}
  24. ## @var{sys} system data structure (@xref{sysstruct})
  25. ## 
  26. ## @strong{Outputs}
  27. ## @table @var
  28. ## @item a,b,c,d
  29. ##  state space matrices for sys
  30. ## 
  31. ## @item tsam
  32. ##  sampling time of sys (0 if continuous)
  33. ## 
  34. ## @item n, nz
  35. ##  number of continuous, discrete states (discrete states come
  36. ##           last in state vector @var{x})
  37. ## 
  38. ## @item stname, inname, outname
  39. ##  signal names (lists of strings);  names of states,
  40. ##           inputs, and outputs, respectively
  41. ## 
  42. ## @item yd
  43. ##  binary vector; @var{yd}(@var{ii}) is 1 if output @var{y}(@var{ii})$
  44. ##  is discrete (sampled); otherwise  @var{yd}(@var{ii}) 0.
  45. ##  
  46. ## @end table
  47. ## A warning massage is printed if the system is a mixed
  48. ## continuous and discrete system
  49. ## 
  50. ## @strong{Example}
  51. ## @example
  52. ## octave:1> sys=tf2sys([1 2],[3 4 5]);
  53. ## octave:2> [a,b,c,d] = sys2ss(sys)
  54. ## a =
  55. ##    0.00000   1.00000
  56. ##   -1.66667  -1.33333
  57. ## b =
  58. ##   0
  59. ##   1
  60. ## c = 0.66667  0.33333
  61. ## d = 0
  62. ## @end example
  63. ## @end deftypefn
  64.  
  65. function [a, b, c, d, tsam, n, nz, stname, inname, outname, yd] = sys2ss (sys)
  66.  
  67.   ## Written by David Clem August 19, 1994
  68.   ## Updates by John Ingram July 14, 1996
  69.  
  70.   if(nargin != 1)
  71.     usage("[a,b,c,d,tsam,n,nz,stname,inname,outname,yd] = sys2ss(sys)")
  72.   endif
  73.  
  74.   if (nargout > 11)
  75.     warning(["sys2ss: ",num2str(nargout)," out arguments exceeds max=11"])
  76.     usage("[a,b,c,d,tsam,n,nz,stname,inname,outname,yd] = sys2ss(sys)")
  77.   endif
  78.  
  79.   if( ! is_struct(sys) )
  80.     error("input argument must be a system data structure");
  81.   endif
  82.  
  83.   sys = sysupdate(sys,"ss");        # make sure state space data is there
  84.   [n,nz,m,p] = sysdimensions(sys);
  85.   [stname,inname,outname,yd] = sysgetsignals(sys);
  86.   tsam = sysgettsam(sys);
  87.  
  88.   cont = sum(yd == 0) + n;
  89.   dig = sum(yd != 0) + nz + tsam;
  90.   if(cont*dig)
  91.     warning("sys2ss: input system is mixed continuous/discrete");
  92.   endif
  93.  
  94.   a = sys.a;
  95.   b = sys.b;
  96.   c = sys.c;
  97.   d = sys.d;
  98.  
  99. endfunction
  100.  
  101.