home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts / control / is_abcd.m < prev    next >
Text File  |  1999-03-05  |  3KB  |  97 lines

  1. # Copyright (C) 1997 Kai P. Mueller
  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 retval = is_abcd(a, b, c, d)
  18.   # ------------------------------------------------------
  19.   # retval = is_abcd(a [, b, c, d])
  20.   # Returns retval = 1 if the dimensions of a, b, c, d
  21.   # are compatible, otherwise retval = 0.
  22.   # The matrices b, c, or d may be omitted.
  23.   # ------------------------------------------------------
  24.   # 
  25.   # see also: abcddim
  26.  
  27.   # Written by Kai P. Mueller November 4, 1997
  28.   # based on is_controllable.m of Scottedward Hodel
  29.   # modified by
  30.  
  31.   retval = 0;
  32.   switch (nargin)
  33.     case (1)
  34.       # A only
  35.       [na, ma] = size(a);
  36.       if (na != ma)
  37.         disp("Matrix A ist not square.")
  38.       endif
  39.     case (2)
  40.       # A, B only
  41.       [na, ma] = size(a);  [nb, mb] = size(b);
  42.       if (na != ma)
  43.         disp("Matrix A ist not square.")
  44.     return;
  45.       endif
  46.       if (na != nb)
  47.         disp("A and B column dimension different.")
  48.         return;
  49.       endif
  50.     case (3)
  51.       # A, B, C only
  52.       [na, ma] = size(a);  [nb, mb] = size(b);  [nc, mc] = size(c);
  53.       if (na != ma)
  54.         disp("Matrix A ist not square.")
  55.     return;
  56.       endif
  57.       if (na != nb)
  58.         disp("A and B column dimensions not compatible.")
  59.     return;
  60.       endif
  61.       if (ma != mc)
  62.         disp("A and C row dimensions not compatible.")
  63.     return;
  64.       endif
  65.     case (4)
  66.       # all matrices A, B, C, D
  67.       [na, ma] = size(a);  [nb, mb] = size(b);
  68.       [nc, mc] = size(c);  [nd, md] = size(d);
  69.       if (na != ma)
  70.         disp("Matrix A ist not square.")
  71.     return;
  72.       endif
  73.       if (na != nb)
  74.         disp("A and B column dimensions not compatible.")
  75.     return;
  76.       endif
  77.       if (ma != mc)
  78.         disp("A and C row dimensions not compatible.")
  79.     return;
  80.       endif
  81.       if (mb != md)
  82.         disp("B and D row dimensions not compatible.")
  83.     return;
  84.       endif
  85.       if (nc != nd)
  86.         disp("C and D column dimensions not compatible.")
  87.     return;
  88.       endif
  89.     otherwise
  90.       usage("retval = is_abcd(a [, b, c, d])")
  91.   endswitch
  92.   # all tests passed, signal ok.
  93.   retval = 1;
  94. endfunction
  95.