Problem with find() and vector assignment using ranges: vector=start:step:stop

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Problem with find() and vector assignment using ranges: vector=start:step:stop

pete.F
Hi,
I'm running octave V4.2.0 on windows and I'm having trouble with the following commands:
>>L=1E-6:0.1E-6:500E-6;
>>find(L==33E-6)
ans= [] (1x0)

33E-6 is located within vector 'L' at index=321. But if I subtract 33E-6 from L(321) I get:

>>L(321)-33E-6
ans=-6.7763E-21

It appears that the scalar 33E-6 and the scalar L(321) don't have the same precision...
I have verified the same functionality on V3.8.2 on windows.
Is this functionality intended?
Is there a better way to check for equality and locate an index?
Thanks in advance.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem with find() and vector assignment using ranges: vector=start:step:stop

tmacchant


--- pete.i.flyn> Hi,

> I'm running octave V4.2.0 on windows and I'm having trouble with the
> following commands:
> >>L=1E-6:0.1E-6:500E-6;
> >>find(L==33E-6)
> ans= [] (1x0)
>
> 33E-6 is located within vector 'L' at index=321. But if I subtract 33E-6
> from L(321) I get:
>
> >>L(321)-33E-6
> ans=-6.7763E-21
>
> It appears that the scalar 33E-6 and the scalar L(321) don't have the same
> precision...
> I have verified the same functionality on V3.8.2 on windows.
> Is this functionality intended?
> Is there a better way to check for equality and locate an index?
> Thanks in advance.
>
Your result is reasonable considering nature of floating point values.

Tatsuro

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem with find() and vector assignment using ranges: vector=start:step:stop

Ozzy Lash
In reply to this post by pete.F


On Fri, Jul 28, 2017 at 12:47 PM, pete.F <[hidden email]> wrote:
Hi,
I'm running octave V4.2.0 on windows and I'm having trouble with the
following commands:
>>L=1E-6:0.1E-6:500E-6;
>>find(L==33E-6)
ans= [] (1x0)

33E-6 is located within vector 'L' at index=321. But if I subtract 33E-6
from L(321) I get:

>>L(321)-33E-6
ans=-6.7763E-21

It appears that the scalar 33E-6 and the scalar L(321) don't have the same
precision...
I have verified the same functionality on V3.8.2 on windows.
Is this functionality intended?
Is there a better way to check for equality and locate an index?
Thanks in advance.


Using one of the suggestions there, you could write your find experession as:

>> find(abs(L-33e-6)<=eps(33e-6))
ans =  321

Bill

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem with find() and vector assignment using ranges: vector=start:step:stop

pete.F
This is news to me. Thanks Bill, that is most helpful.
Cheers.
Pete
Loading...