# ismembertol does not work as documented

14 views (last 30 days)
Bessam Al Jewad on 20 Aug 2019
Commented: Guillaume on 21 Aug 2019
Hello,
This function should work with absolute tolerance. Here is an example where it doesn't work as documented
B=[ 1.9500 1.0000];
A=[3.0000 2.0000 4.0000 2.5000 1.2000 1.1000];
[Loc1,Loc2]=ismembertol(B,A,0.1,'DataScale',1)
What should come out according to documentation is
Loc1 =
1×2 logical array
1 1
Loc2 =
2 6
What does come out however is
Loc1 =
1×2 logical array
1 0
Loc2 =
2 0
It seems someone forgot the absolute when comparing :)

Matt J on 20 Aug 2019
Edited: Matt J on 20 Aug 2019
The documentation isn't wrong. You've set a tolerance that can only satisfied reliably at A(6) in infinite precision arithmetic. Observe:
>> [Loc1,Loc2]=ismembertol(B,A,0.1+eps,'DataScale',1)
Loc1 =
1×2 logical array
1 1
Loc2 =
2 6

Guillaume on 20 Aug 2019
To clarify, 1.1 is not actually representable as a double. What's actual stored in memory is 1.100000000000000088817841970012523233890533447265625. Similarly 0.1 is not actually representable as double (exact value is 0.1000000000000000055511151231257827021181583404541015625), The difference between actual value of 1.1 and 1 is slightly larger than that:
>> (1.1 - 1) <= 0.1
ans =
logical
0
so, yes ismembertol is going to say that 1.1 is not within range.
Matt J on 21 Aug 2019
Hmmm. But 1.100000000000000088817841970012523233890533447265625 looks higher than double precision (more than 16 decimal points) ?
Guillaume on 21 Aug 2019
It's the complete expansion of the binary fraction. I used Jame Tursa's num2strexact for that. As James says on that page, Don't confuse the exact conversion with significance. These extra digits are just noise. The double before 1.1 is:
>> num2strexact(1.1-eps(1.1))
ans =
'1.0999999999999998667732370449812151491641998291015625'
and the difference between the two is
>> eps(1.1) %1.1-eps(1.1) has the same eps
ans =
2.2204e-16
as you can see the difference is around 1e-16 so at the 16th digit.