From: David Young on
Parker <xenoszh(a)gmail.com> wrote in message <c753e854-c76d-4f9e-b24b-8a50bf157035(a)y12g2000vbg.googlegroups.com>...
> ...
> always test equal like
>
> >> x1 = [1/3 repmat(2/3,1,10)]';
> >> x2 = [repmat(2/3,1,10) 1/3]';
>
> >> if (mean(x1)-mean(x2))<eps
> disp('Equal');
> else
> disp('Unequal');
> end

Not quite correct. Try the above with, for example, x2 = ones(size(x1)) and you'll find it will still report 'Equal'. What is needed is to take the absolute value of the difference:

if abs(mean(x1)-mean(x2))<eps

This is only correct if eps is the right tolerance. It often will be appropriate, but not always - it depends on the details of the computation that leads up to the test.
First  |  Prev  | 
Pages: 1 2
Prev: Curve matching question
Next: Mark S whorton