Re: Value close to zero.
- From: "Roger Stafford" <ellieandrogerxyzzy@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 14 Apr 2008 17:19:04 +0000 (UTC)
"David " <dave@xxxxxxxxxxxxxx> wrote in message <ftvcqt$mk5
$1@xxxxxxxxxxxxxxxxxx>...
"Sebastiaan " <s.breedveld@xxxxxxxxxxxxxxxxxxxxxxxxxxx>---------
wrote in message <ftv8nm$hkv$1@xxxxxxxxxxxxxxxxxx>...
In addition to the explanation of Roger, checking if a
floating point value is zero may become a problem.
E.g. this:
if x==0
might not work if x is a floating point number, since it
might contain round-off errors. Instead, check if x is
within the machine precision:
if x<eps
Regards,
Sebastiaan
note that you want to check the absolute value of x
against eps since roundoff error can result in small
negative numbers also.
Just comparing some quantity x with matlab's 'eps' is not an adequate test
for its being essentially zero or otherwise. What it should be tested against
depends, first of all, on the size of the numbers from which it was computed,
and second on the nature of the computations that were performed.
For example, if we have
x = 1e43*(cos(pi/3)-1/2);
which ought to be zero if it were not for rounding errors, a single bit
rounding error in computing cos(pi/3)-1/2 will be magnified by the
enormous factor of 1e43, so we should therefore be using eps(1e43) instead
of simply eps.
If we have
x = sum(sin(2*pi/1000000*(1:1000000)));
which ideally should also be zero, we have to take into consideration the total
number of summands used here. The accumulated error due to rounding in a
million terms will amount to a very much larger error than a simple eps.
Allowing for the proper tolerance in distinguishing between quantities that
are likely to differ from zero only because of rounding errors, as opposed to
those whose values are significantly different from zero, is a task that
requires some degree of care - something that takes into account the
magnitude of expected rounding errors at all stages of the computation that
led up to the numbers.
Roger Stafford
.
- References:
- Value close to zero.
- From: HORMIS
- Re: Value close to zero.
- From: Sebastiaan
- Re: Value close to zero.
- From: David
- Value close to zero.
- Prev by Date: Re: Need a bootcamp
- Next by Date: Cell Folding?
- Previous by thread: Re: Value close to zero.
- Next by thread: edge
- Index(es):
Relevant Pages
|