Elegant algorithm for finding abs min > tol

Lopaka(Rob) Lee rlee@fpcc.net
Tue Feb 18 23:56:00 GMT 2003


Can anyone suggest some GSL code to find a vector element with the 
smallest absolute value _greater than_ a specified tolerance?

Below is my shameful hack.

double gslExt_vector_absmin(const gsl_vector *v, double tol)
/**
 * Find absolute minimum element of gsl_vector that is
 * greater than a specified tol.  Assumes vector is not null.
 */
{
    double min = DBL_MAX; // IEEE double maximum
    for (size_t i = 0; i < v->size; i++)
      {
        double next = fabs(gsl_vector_get(v, i));
        if (next < tol) continue;
        if (next < min) min = next;
      }
    return min;
}




More information about the Gsl-discuss mailing list