Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Topic: Replacing `find` with logical indexing
Replies: 6   Last Post: Jul 10, 2013 1:47 PM

 Messages: [ Previous | Next ]
 Jeff Posts: 113 Registered: 11/22/09
Re: Replacing `find` with logical indexing
Posted: Jul 10, 2013 10:55 AM

dpb <none@non.net> wrote in message <krikfe\$o13\$1@speranza.aioe.org>...
> On 7/9/2013 9:24 PM, TideMan wrote:
> > On Wednesday, July 10, 2013 1:20:34 PM UTC+12, dpb wrote:
> ...
> > And with floating point numbers, shouldn't it be:
> > DNZmin=min(abs(D(abs(D)>tol)));
> > where tol is a small number like 1e-6

>
> ...
>
> If in the original code the lambda in the comparison were some other fp
> value, then your recommendation/concern is right on. But in the actual
> code lambda is min() of of the same vector so it's identical by that
> process of selection already and the existence of a value off by only
> LSB in the mantissa if it were to exist is already out, anyway. But the
> missed comparison of a value entered at the keyboard trying to compare
> to one computed internally as is so often the cause of the FAQ question
> doesn't arise here.
>

Isn't TideMan right? The inner parenthesis comparison, D~=0, is comparing floating point numbers in D to 0. If there is a very, very small value of D, say 1e-20, which really should be zero, I don't want that value returned. In your case, since I didn't specify how D was created, shouldn't you have included that?

FYI: D is created as follows:
for jj = 1:N
for kk = 1:N
idxVal = (jj-1)*N + k;
D(idxVal)=4-2*cosd((jj*180)/(N+1)) - 2*cosd((kk*180)/(N+1));
end
end

N is an integer, power of 2, at least 8 (e.g., 8, 16, 32,...). I'm pretty sure I can get away with D~=0, but I'm curious how you knew that without knowing D.

Date Subject Author
7/9/13 Jeff
7/9/13 dpb
7/9/13 Jeff
7/9/13 Derek Goring
7/9/13 dpb
7/10/13 Jeff
7/10/13 dpb