Potential bug in pdist or variable savings??
1 view (last 30 days)
Show older comments
Hi,
I've been running a little program which generates a vector called "past_ctry". Everything in past_ctry is evaluated as 48.281. However when I use this variable and explicit 48.281 in pdist. I got different result with one is 0.001005 and the other is 0.00074012. Could someone explain why? The data can be found in this link:
And the program is following:
clear all; close all; clc;
load('abc')
x1 = 1.573;
y1 = 48.282;
x2 = 1.5731;
y2 = 48.281;
y2_new = past_ctry(1); % past_ctry(1) is also 48.281
pdist([x1, y1; x2, y2]) % result is 0.001005
pdist([x1, y1; x2, y2_new]) % result is 0.00074012
0 Comments
Accepted Answer
John D'Errico
on 1 Dec 2015
Edited: John D'Errico
on 1 Dec 2015
Congratulations! You are the 10 millionth person to find a this "bug".
Except, it is not a bug. What has happened is the actual value of one (or both) of those numbers is not actually 48.281. It is probably just a wee bit off, and it was displayed using limited precision. So you THINK the value is exactly 48.281, but, NOT.
Watch out when a number is displayed with only 5 digits of precision. Numbers are stored as doubles in Matlab.
1 Comment
Walter Roberson
on 1 Dec 2015
What is stored is
48.28126666666667432536996784619987010955810546875
which is about 0.000266666666675519 larger than 48.281
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!