why does matlab distance function returns odd errors for specific doubles, how to fix?
Show older comments
Matlab distance function found here: /usr/local/apps/matlab-2013a/toolbox/map/map/distance.m generates an error when I give it certain values.
one example is that it would not work for these
[hex2num('bff302fba03a0023'),hex2num('4003ff6217b27e6b'),hex2num('3ff302fba03a0023'),hex2num('bfe48a64f246bab5')]
ans =
-1.1882 2.4997 1.1882 -0.6419
when plugged in as so:
distance(hex2num('bff302fba03a0023'),hex2num('4003ff6217b27e6b'),hex2num('3ff302fba03a0023'),hex2num('bfe48a64f246bab5'),'radians')
I get this error:
Error using atan2 Inputs must be real.
Error in distance>greatcircledist (line 160) rng = r * 2 * atan2(sqrt(a),sqrt(1 - a));
Error in distance (line 101) rng = greatcircledist(lat1, lon1, lat2, lon2, ellipsoid(1));
however rounding the values to
distance(-1.1882 , 2.4997 , 1.1882 , -0.6419,'radians')
works fine and returns 3.1416
1 Comment
Chad Greene
on 21 Jun 2016
Interesting question. I am able to replicate the problem, but I don't know the cause.
Accepted Answer
More Answers (0)
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!