home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts.fat / control / sysupdat.m < prev    next >
Text File  |  1999-04-29  |  4KB  |  107 lines

  1. # Copyright (C) 1996 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 sys = sysupdat(sys,opt)
  18. # function retsys = sysupdat(sys,opt)
  19. # Update the internal representation of a system.
  20. # inputs:
  21. #  sys: system data structure
  22. #  opt: string:  "tf" -> update transfer function
  23. #                "zp" -> update zero-pole form
  24. #                "ss" -> update state space form
  25. #                "all" -> all of the above
  26. # outputs: retsys: contains union of data in sys and requested data.
  27. #     if requested data in sys is already up to date then retsys=sys.
  28. #
  29. # conversion to tf or zp exits with an error if the system is
  30. # mixed continuous/digital
  31. #
  32. # see also: tf2sys, ss2sys, zp2sys, sysout, sys2ss, sys2tf, sys2zp
  33.  
  34. # Written by John Ingram  7-9-96
  35.  
  36.   # check for correct number of inputs 
  37.   if (nargin != 2)
  38.     usage("newsys = sysupdat(sys,opt)");
  39.   elseif(! is_struct(sys) )
  40.    error("1st argument must be system data structure")
  41.   elseif(! (strcmp(opt,"tf") + strcmp(opt,"zp") + ...
  42.     strcmp(opt,"ss") + strcmp(opt,"all")) )
  43.     error("2nd argument must be \"tf\", \"zp\", \"ss\", or \"all\"");
  44.   endif
  45.  
  46.   # check to make sure not trying to make a SISO system out of a MIMO sys
  47.   if ( (strcmp(opt,"tf") + strcmp(opt,"zp") + strcmp(opt,"all")) ...
  48.     & strcmp(sysgetty(sys),"ss") &  (! is_siso(sys) ) )
  49.     error("MIMO -> SISO update requested");
  50.   endif
  51.  
  52.   # update transfer function if desired
  53.   if ( (strcmp(opt, "tf") + strcmp(opt,"all"))&&  (!sys.sys(2)))
  54.     # check to make sure the system is not discrete and continuous
  55.     is_digit(sys);
  56.  
  57.     # if original system zero-pole
  58.     if strcmp(sysgetty(sys),"zp")
  59.       [sys.num,sys.den] = zp2tf(sys.zer,sys.pol,sys.k);
  60.       sys.sys(2) = 1;
  61.     # if original system is state-space
  62.     elseif(sys.sys(1) == 2)
  63.       [sys.num,sys.den] = ss2tf(sys.a,sys.b,sys.c,sys.d);
  64.       sys.sys(2) = 1; 
  65.     endif
  66.   endif
  67.  
  68.  
  69.   # update zero-pole if desired
  70.   if ( (strcmp(opt, "zp") + strcmp(opt,"all")) && (! sys.sys(3)) )
  71.     # check to make sure the system is not discrete and continuous
  72.     is_digit(sys);
  73.  
  74.     # original system is transfer function
  75.     if (sys.sys(1) == 0)
  76.       [sys.zer,sys.pol,sys.k] = tf2zp(sys.num,sys.den);
  77.       sys.sys(3) = 1;
  78.     # original system is state-space
  79.  
  80.     elseif(sys.sys(1) == 2)
  81.       [sys.zer,sys.pol,sys.k] = ss2zp(sys.a,sys.b,sys.c,sys.d);
  82.       sys.sys(3) = 1; 
  83.     endif
  84.  
  85.   endif
  86.  
  87.   # update state-space if desired
  88.   if ( (strcmp(opt, "ss") + strcmp(opt,"all")) && (! sys.sys(4)) )
  89.     # original system is transfer function
  90.     if (sys.sys(1) == 0)
  91.       [sys.a,sys.b,sys.c,sys.d] = tf2ss(sys.num,sys.den);
  92.       sys.sys(4) = 1;
  93.     # original system is zero-pole
  94.     elseif(sys.sys(1) == 1)
  95.       [sys.a,sys.b,sys.c,sys.d] = zp2ss(sys.zer,sys.pol,sys.k);
  96.       sys.sys(4) = 1; 
  97.     endif
  98.  
  99.     # create new state names
  100.     sys.stname = sysdefst(sys.n, sys.nz);
  101.   endif
  102.   
  103.  
  104. endfunction
  105.