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

  1. ## Copyright (C) 1993, 1994, 1995 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{n}, @var{m}, @var{p}] =} abcddim (@var{a}, @var{b}, @var{c}, @var{d})
  21. ## Check for compatibility of the dimensions of the matrices defining
  22. ## the linear system
  23. ## @iftex
  24. ## @tex
  25. ## $[A, B, C, D]$ corresponding to
  26. ## $$
  27. ## \eqalign{
  28. ##  {dx\over dt} &= A x + B u\cr
  29. ##             y &= C x + D u}
  30. ## $$
  31. ## @end tex
  32. ## @end iftex
  33. ## @ifinfo
  34. ## [A, B, C, D] corresponding to
  35. ## 
  36. ## @example
  37. ## dx/dt = a x + b u
  38. ## y = c x + d u
  39. ## @end example
  40. ## 
  41. ## @end ifinfo
  42. ## or a similar discrete-time system.
  43. ## 
  44. ## If the matrices are compatibly dimensioned, then @code{abcddim} returns
  45. ## 
  46. ## @table @var
  47. ## @item n
  48. ## The number of system states.
  49. ## 
  50. ## @item m
  51. ## The number of system inputs.
  52. ## 
  53. ## @item p
  54. ## The number of system outputs.
  55. ## @end table
  56. ## 
  57. ## Otherwise @code{abcddim} returns @var{n} = @var{m} = @var{p} = @minus{}1.
  58. ## 
  59. ## Note: n = 0 (pure gain block) is returned without warning.
  60. ## 
  61. ## See also: is_abcd
  62. ## @end deftypefn
  63.  
  64. function [n, m, p] = abcddim (a, b, c, d)
  65. ## Written by A. S. Hodel (scotte@eng.auburn.edu) August 1993.
  66. ## a s hodel: modified to accept pure-gain systems aug 1996
  67.  
  68.   if (nargin != 4)
  69.     error ("abcddim: four arguments required");
  70.   endif
  71.  
  72.   n = m = p = -1;
  73.  
  74.   [a,an,am] = abcddims(a);
  75.   [b,bn,bm] = abcddims(b);
  76.   [c,cn,cm] = abcddims(c);
  77.   [d,dn,dm] = abcddims(d);
  78.  
  79.   if ( (!is_square(a)) & (!isempty(a)) )
  80.     warning (["abcddim: a is not square (",num2str(an),"x",num2str(am),")"]);
  81.     return
  82.   endif
  83.  
  84.   if( (bm == 0) & (dm == 0) )
  85.     warning("abcddim: no inputs");
  86.   elseif (bn != am)
  87.     warning (["abcddim: a(",num2str(an),"x",num2str(am), ...
  88.       " and b(",num2str(bn),"x",num2str(bm),") are not compatible"]);
  89.     return
  90.   endif
  91.  
  92.   if( (cn == 0) & (dn == 0 ) )
  93.     warning("abcddim: no outputs");
  94.   elseif (cm != an)
  95.     warning (["abcddim: a(",num2str(an),"x",num2str(am), ...
  96.     " and c(",num2str(cn),"x",num2str(cm),") are not compatible"]);
  97.     return
  98.   endif
  99.  
  100.   have_connections = (bn*cn != 0);
  101.  
  102.   if( (dn == 0) & have_connections)
  103.     warning("abcddim: empty d matrix passed; setting compatibly with b, c");
  104.     [d,dn,dm] = abcddims(zeros(cn,bm));
  105.   endif
  106.  
  107.   if(an > 0)
  108.     [dn, dm] = size(d);
  109.     if ( (cn != dn) & have_connections )
  110.       warning (["abcddim: c(",num2str(cn),"x",num2str(cm), ...
  111.     " and d(",num2str(dn),"x",num2str(dm),") are not compatible"]);
  112.       return
  113.     endif
  114.  
  115.     if ( (bm != dm) & have_connections )
  116.       warning (["abcddim: b(",num2str(bn),"x",num2str(bm), ...
  117.       " and d(",num2str(dn),"x",num2str(dm),") are not compatible"]);
  118.       return
  119.     endif
  120.  
  121.     m = bm;
  122.     p = cn;
  123.   else
  124.     [p,m] = size(d);
  125.   endif
  126.   n = an;
  127. endfunction
  128.