Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Range operator

21 views
Skip to first unread message

malcolm....@kcl.ac.uk

unread,
Apr 24, 2012, 4:26:35 PM4/24/12
to
v=1-2^-52:(2^-52)/4:1+2^-52
returns an 11 element vector (cf 9 in MATLAB).

In the SciLab result, the final element is outside of the specified
range

v>1+2^-52
ans =

F F F F F F F F F F T

This looks like a bug.

Jean-Pierre Vial

unread,
Apr 24, 2012, 5:25:29 PM4/24/12
to
-->v-1
ans =

1.0D-15 *


column 1 to 8

- 0.2220446 - 0.2220446 - 0.1110223 0. 0. 0. 0.
0.2220446

column 9 to 11

0.2220446 0.2220446 0.4440892

the computation is not reliable: you are not in the safe range of ieee
arithmetic. The increment 2^(-54) is too small compared to 1.

malcolm....@kcl.ac.uk

unread,
Apr 24, 2012, 7:25:46 PM4/24/12
to
True, but the algorithm should at least limit the returned vector to
the range specidied i.e 1+eps.
Here the final value is 1+2*eps. Expected answer accounting for IEEE
and providing the expected 9 element output reflecting 8 intervals:
[1-eps 1-eps 1-eps/2 1 1 1 1 1+eps 1+eps]

See:
http://www.mathworks.co.uk/support/solutions/en/data/1-4FLI96/index.html?solution=1-4FLI

Serge Steer

unread,
Apr 27, 2012, 11:30:34 AM4/27/12
to
Le 24/04/2012 22:26, malcolm....@kcl.ac.uk a écrit :
Such use of range operator is unreliable due to rounding errors.
It is better using
v=1+(-4:4)*2^(-52)/4
This latter syntax will give 9 values none of them are greater than 1+2^-52.

Note however that
-->diff(v)
ans =

0. 1.110D-16 1.110D-16 0. 0. 0. 2.220D-16 0.

and with Matlab
>> diff(v)

ans =

1.0e-15 *

0 0.1110 0.1110 0 0 0 0.2220 0

So the result is wrong in any case (distance between 2 consecutive
values may be 0).

Serge Steer
0 new messages