annotate toolboxes/FullBNT-1.0.7/GraphViz/approxeq.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function p = approxeq(a, b, tol, rel)
wolffd@0 2 % APPROXEQ Are a and b approximately equal (to within a specified tolerance)?
wolffd@0 3 % p = approxeq(a, b, thresh)
wolffd@0 4 % 'tol' defaults to 1e-3.
wolffd@0 5 % p(i) = 1 iff abs(a(i) - b(i)) < thresh
wolffd@0 6 %
wolffd@0 7 % p = approxeq(a, b, thresh, 1)
wolffd@0 8 % p(i) = 1 iff abs(a(i)-b(i))/abs(a(i)) < thresh
wolffd@0 9
wolffd@0 10 if nargin < 3, tol = 1e-2; end
wolffd@0 11 if nargin < 4, rel = 0; end
wolffd@0 12
wolffd@0 13 a = a(:);
wolffd@0 14 b = b(:);
wolffd@0 15 d = abs(a-b);
wolffd@0 16 if rel
wolffd@0 17 p = ~any( (d ./ (abs(a)+eps)) > tol);
wolffd@0 18 else
wolffd@0 19 p = ~any(d > tol);
wolffd@0 20 end
wolffd@0 21