Problem with a statement in code.

on 30 Sep 2011

Walter Roberson (view profile)

Hi Guys,
I am facing problems with one statement "yfound = yi(abs(xi-findyatx)<eps);"
If the array xi has the same element as that of findyatx, that location will have an value of 1 while all others will have zero. I can see that there is an element in xi that has the same value as that of findyatx. But still all I get as a answer for yfound is an empty matrix.

Walter Roberson (view profile)

on 30 Sep 2011

It is not a good idea to use eps as the tolerance, as eps by itself is eps(1) which is less than the distance between adjacent numbers by the time you get to even just 2. You should use max(eps(xi),eps(findyatx)) at the very least, and multiples of that are usually better.

Nancy

Nancy (view profile)

on 30 Sep 2011
Thanks Walter. How would you use max(eps(xi),eps(findyatx)) in that code.? I used 0.00001 instead of eps and the code seemed to work fine.
Thanks once again.
Walter Roberson

Walter Roberson (view profile)

on 30 Sep 2011
tolerance = 10 * max(eps(xi),eps(findyatx));
yfound = yi(abs(xi-findyatx)<tolerance)