home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l455 / 2.ddi / MUTOOLS1.DI$ / INDVCMP.M < prev    next >
Encoding:
Text File  |  1993-03-11  |  2.5 KB  |  82 lines

  1. % function code = indvcmp(mat1,mat2,errcrit)
  2. %
  3. %   Compares the INDEPENDENT VARIABLE data for two VARYING matrices:
  4. %       CODE = 0; varying data is different
  5. %       CODE = 1; varying data is identical OR both are CONSTANT matrices
  6. %       CODE = 2; different number of points
  7. %       CODE = 3; matrices are not both VARYING, or not both CONSTANT
  8. %
  9. %       ERRCRIT - 1x2 optional matrix containing the relative 
  10. %          error and absolute error bounds. The relative error
  11. %          is used to test error in independent variables whose
  12. %          magnitude is greater than 1e-9, while the absolute
  13. %          error bound used for smaller independent variable
  14. %          values. Default values are 1e-6, and 1e-13, respectively.
  15. %
  16. %   See also: GETIV, SORTIV, VUNPCK, XTRACT, and XTRACTI.
  17.  
  18. function ccode = indvcmp(mat1,mat2,errcrit)
  19.  if nargin < 2
  20.    disp('usage: code = indvcmp(mat1,mat2)')
  21.    return
  22.  elseif nargin == 2
  23.    relerr = 1e-6;
  24.    abserr = 1e-13;
  25.  else
  26.    [ecr,ecc] = size(errcrit);
  27.    if ecr == 1 & ecc == 2
  28.      relerr = errcrit(1);
  29.      abserr = errcrit(2);
  30.    else
  31.      error('errcrit (3rd argument) should be a 1x2 matrix')
  32.      return
  33.    end
  34.  end
  35.  code = 1;
  36.  [m1type,m1r,m1c,m1n] = minfo(mat1);
  37.  [m2type,m2r,m2c,m2n] = minfo(mat2);
  38.  if strcmp(m1type,'vary') & strcmp(m2type,'vary')
  39.    if m1n == m2n
  40.      nrlyzero = find(abs(mat1(1:m1n,m1c+1))<1e-9);
  41. %                  ind variables for mat1 that are less than 1e-9
  42.      if length(nrlyzero) == 0
  43.        relerrs = (mat2(1:m1n,m2c+1)-mat1(1:m1n,m1c+1)) ./ mat1(1:m1n,m1c+1);
  44.        if max(abs(relerrs)) > relerr
  45.          code = 0;
  46.        end
  47.      else
  48.        notnz = comple(nrlyzero,m1n);
  49.        nzerr = max(abs(mat1(nrlyzero,m1c+1)-mat2(nrlyzero,m2c+1)));
  50.        relerrs = (mat2(notnz,m2c+1)-mat1(notnz,m1c+1)) ./ mat1(notnz,m1c+1);
  51.        if nzerr > abserr | max(abs(relerrs)) > relerr
  52.          code = 0;
  53.        end
  54.      end
  55.    else
  56.      code = 2;
  57.    end
  58.  elseif strcmp(m1type,'cons') & strcmp(m2type,'cons')
  59.    code = 1;
  60.  else
  61.    code = 3;
  62.  end
  63.  if nargout == 0
  64.    if code == 1
  65.      if strcmp(m1type,'vary')
  66.        disp('varying data is the same')
  67.      else
  68.        disp('both are CONSTANT matrices')
  69.      end
  70.    elseif code == 0
  71.      disp('varying data is DIFFERENT')
  72.    elseif code == 2
  73.      disp('different number of independent variable values')
  74.    else
  75.      disp('matrices are not both VARYING, or not both CONSTANT')
  76.    end
  77.  else
  78.    ccode = code;
  79.  end
  80. %
  81. % Copyright MUSYN INC 1991,  All Rights Reserved
  82.