How can I find the position of a real number in a vector?
3 visualizzazioni (ultimi 30 giorni)
James Tursa il 5 Mar 2020
Modificato: James Tursa il 5 Mar 2020
Welcome to the world of floating point arithmetic. The number you are searching for cannot be represented exactly in IEEE double precision, so calculations involving it are subject to roundoff errors.
You will need to do the search with some tolerance. E.g.,
find( abs(x - (-0.9990)) < 1e-10 )
P.S. Your example actually does work if you use "v" instead of "x". I am assuming your actual v is built differently. Or maybe the typo is the entire problem.