This is the mail archive of the
gsl-discuss@sources.redhat.com
mailing list for the GSL project.
Elegant algorithm for finding abs min > tol
- From: "Lopaka(Rob) Lee" <rlee at fpcc dot net>
- To: gsl-discuss at sources dot redhat dot com
- Date: Tue, 18 Feb 2003 17:04:13 -0700 (MST)
- Subject: 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;
}