This is the mail archive of the gsl-discuss@sources.redhat.com mailing list for the GSL project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Elegant algorithm for finding abs min > tol


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;
}



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]