[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: eps function and numerical accuracy
From: |
Daniel J Sebald |
Subject: |
Re: eps function and numerical accuracy |
Date: |
Mon, 08 Jul 2013 19:14:49 -0500 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111108 Fedora/3.1.16-1.fc14 Thunderbird/3.1.16 |
On 07/08/2013 06:41 PM, Nir Krakauer wrote:
As in your example, assert works element-by-element -- i.e. it will
return an error if any two elements in the input arguments differ by
more than the specified tolerance
Well, at first blush it seems that way, but this error:
maximum absolute error 4.44089e-16 exceeds tolerance 2.71333e-166
makes me wonder because the absolute error associated with the first
element isn't near that magnitude. That's actually the other end of the
vector.
Here is a simple example:
assert([1 2], [0, 0], [1 2])
assert([1 2], [0, 0], [1 1])
error: assert ([1, 2],[0, 0],[1, 1]) expected
0 0
but got
1 2
maximum absolute error 2 exceeds tolerance 1maximum absolute error 1
exceeds tolerance
error: called from:
error:
/usr/local/src/octave/octave/build-gui-11/../octave/scripts/testfun/assert.m
at line 235, column 5
The first test is fine. The second error is correct, but why it is
indicating "maximum absolute error 1 exceeds tolerance" I'm not sure...
looking at the assert() function:
if (tol == 0)
err = any (A != B);
errtype = "values do not match";
elseif (tol >= 0)
err = max (abs (A - B));
errtype = "maximum absolute error %g exceeds tolerance %g";
else
abserr = max (abs (A(B == 0)));
A = A(B != 0);
B = B(B != 0);
relerr = max (abs (A - B) ./ abs (B));
err = max ([abserr; relerr]);
errtype = "maximum relative error %g exceeds tolerance %g";
endif
if (err > abs (tol))
iserror = 1;
coda = sprintf (errtype, err, abs (tol));
endif
it looks like "tol" must be a scalar in order to operate sanely. I see
now why the error message is coming out so strange when I provide a
vector for tol. The sprintf routine prints multiple lines for "tol"
vector, even if there is no failure associated with the index in question.
It seems like it shouldn't be too difficult to alter assert(.,.,tol) so
that tol can be a vector. Rik (others) do we want to make this change
so that we can fine tune tests like binocdf() and the many other similar
types of functions?
Dan