home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fb.zip / octave / SCRIPTS.ZIP / scripts / control / sysout.m < prev    next >
Encoding:
Text File  |  1999-12-15  |  3.9 KB  |  151 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 } { } sysout ( @var{sys}@{, @var{opt}@}) 
  21. ##  print out a system data structure in desired format
  22. ## @table @var
  23. ## @item  sys
  24. ##  system data structure
  25. ## @item  opt
  26. ## Display option
  27. ## @table @code
  28. ## @item []
  29. ##  primary system form (default); see @ref{sysgettype}.
  30. ## @item      "ss"
  31. ##  state space form
  32. ## @item      "tf"
  33. ##  transfer function form
  34. ## @item      "zp"
  35. ##  zero-pole form
  36. ## @item      "all"
  37. ##  all of the above
  38. ## @end table
  39. ## @end table
  40. ## @end deftypefn
  41.  
  42. function retsys = sysout (sys, opt)
  43.  
  44.   ## Written by A S Hodel: 1995-1996
  45.  
  46.   if( (nargin < 1) || (nargin > 2) )
  47.     usage("sysout(sys[,opt])");
  48.   endif
  49.  
  50.   if(isempty(sys))
  51.     retsys = sys;
  52.     warning("sysout: empty system")
  53.     return;
  54.   endif
  55.  
  56.   if(! is_struct(sys))
  57.     disp("sysout: input must be a system structure")
  58.   endif
  59.  
  60.   ## set up output type array
  61.   if( nargin == 1 )
  62.     opt = sysgettype(sys);
  63.   else
  64.     if( ! (strcmp(opt,"ss") + strcmp(opt,"tf") + ...
  65.       strcmp(opt,"zp") + strcmp(opt,"all") ) )
  66.       error("opt must be one of [], \"ss\", \"tf\", \"zp\", or \"all\"");
  67.     endif
  68.   endif
  69.  
  70.   ## now check output for each form:
  71.   [nn,nz,mm,pp] = sysdimensions(sys);
  72.   if( mm > 0)
  73.     disp("Input(s)")
  74.     disp(outlist(sysgetsignals(sys,"in"),"    "));
  75.   else
  76.     disp("Input(s): none");
  77.   endif
  78.   if (pp > 0)
  79.     disp("Output(s):")
  80.     disp(outlist(sysgetsignals(sys,"out"), ...
  81.       "    ",sysgetsignals(sys,"yd")) );
  82.   else
  83.     disp("Output(s): none");
  84.   endif
  85.   if(sysgettsam(sys) > 0)
  86.     disp(["Sampling interval: ",num2str(sysgettsam(sys))]);
  87.     str = "z";
  88.   else
  89.     str = "s";
  90.   endif
  91.  
  92.   ## transfer function form
  93.   if( strcmp(opt,"tf") + strcmp(opt,"all") )
  94.     sys = sysupdate(sys,"tf");        #make sure tf is up to date
  95.     disp("transfer function form:")
  96.     [num,den] = sys2tf(sys);
  97.     tfout(num,den,str);
  98.   endif
  99.  
  100.   if( strcmp(opt,"zp") + strcmp(opt,"all") )
  101.     sys = sysupdate(sys,"zp");        #make sure zp is up to date
  102.     disp("zero-pole form:")
  103.     [zer,pol,kk] = sys2zp(sys);
  104.     zpout(zer, pol, kk,str)
  105.   endif
  106.  
  107.   if( strcmp(opt,"ss") + strcmp(opt,"all") )
  108.     sys = sysupdate(sys,"ss");
  109.     disp("state-space form:");
  110.     disp([num2str(nn)," continuous states, ", num2str(nz)," discrete states"]);
  111.     if( nn+nz > 0)
  112.       disp("State(s):")
  113.       xi = (nn+1):(nn+nz);
  114.       xd = zeros(1,nn+nz);
  115.       if(!isempty(xi))
  116.     xd(xi) = 1;
  117.       endif
  118.       disp(outlist(sysgetsignals(sys,"st"),"    ",xd));
  119.     else
  120.       disp("State(s): none");
  121.     endif
  122.  
  123.     ## display matrix values?
  124.     dmat = (max( [ (nn+nz), mm, pp ] ) <= 32);
  125.  
  126.     printf("A matrix: %d x %d\n",sysdimensions(sys,"st"),
  127.        sysdimensions(sys,"st"));
  128.     [aa,bb,cc,dd] = sys2ss(sys);
  129.     if(dmat)     disp(aa);     endif
  130.  
  131.     printf("B matrix: %d x %d\n",sysdimensions(sys,"st"),
  132.        sysdimensions(sys,"in"));
  133.     if(dmat)     disp(bb);              endif
  134.  
  135.     printf("C matrix: %d x %d\n",sysdimensions(sys,"out"),
  136.        sysdimensions(sys,"st"));
  137.     if(dmat) disp(cc);        endif
  138.  
  139.     printf("D matrix: %d x %d\n",sysdimensions(sys,"out"),
  140.        sysdimensions(sys,"in"));
  141.     if(dmat)       disp(dd);         endif
  142.   endif
  143.  
  144.   if(nargout >= 1)
  145.     retsys = sys;
  146.   endif 
  147.  
  148.   ## restore global variable
  149.  
  150. endfunction
  151.