[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## Re: for loop on decimal numbers fails.

**From**: |
Mike Miller |

**Subject**: |
Re: for loop on decimal numbers fails. |

**Date**: |
Wed, 20 Jul 2016 09:32:33 -0700 |

**User-agent**: |
Mutt/1.6.0 (2016-04-01) |

On Tue, Jul 19, 2016 at 14:34:33 -0700, Swiss_Knight wrote:
>* Hi, *
>* thanks for the fast reply, and yes, it was a typo, sorry.*
>* *
>* Nice trick, it helps, but I still have a strange error :*
>* *
>* A=[sort(repmat ([1:1:10]',[4,1])), repmat([5:5:20]',[10;1]), rand(40,1)];*
>* A(:,1)=A(:,1)/10;*
>* A(:,2)=A(:,2)/10;*
>* *
>* I=0.1:0.1:1; *
>* J=0.5:0.5:2; *
>* *
>* for i_index=1:length(I);*
>* i=I(i_index);*
>* for j_index=1:length(J); *
>* j=J(j_index);*
>* A((find((A(:,1)==i))))*
>* endfor;*
>* endfor;*
>* *
>* It fails for i=0.3 and i=0.7. (seems like a numerical computing issue ?!)*
Yes. Octave does not compute numbers in arbitrary precision, and the
numbers [1:4, 6:9]./10 are not exactly representable. This is one of our
frequently asked questions on this list:
http://wiki.octave.org/FAQ#Why_is_this_floating_point_computation_wrong.3F
--
mike