Instead of using accel_find, consider using gsl_interp_bsearch. The documentation in gsl-1.10/interp/bsearch.c for this function is given below.
It is also simple to rewrite the accel_find function slightly, as I did in C++ for O2scl at http://o2scl.sourceforge.net/o2scl/html/search__vec_8h-source.html Take care, Andrew /* * Note that this means the relationship of 'x' to x_array[index] * and x_array[index+1] depends on the result region, i.e. the * behaviour at the boundaries may not correspond to what you * expect. We have the following complete specification of the * behaviour. * Suppose the input is x_array[] = { x0, x1, ..., xN } * if ( x == x0 ) then index == 0 * if ( x > x0 && x <= x1 ) then index == 0, and sim. for other interior pts * if ( x == xN ) then index == N-1 * if ( x > xN ) then index == N-1 * if ( x < x0 ) then index == 0 */ ----- Original Message ---- From: Daniel J Farrell <[EMAIL PROTECTED]> To: [email protected] Sent: Tuesday, October 23, 2007 8:26:49 AM Subject: [Help-gsl] Question about interpolation Hello, I am using gsl_interp.h functions to look-up the index of a C array which is the nearest to the value, x. However if the value of the x is the maximum value of the array GSL doesn't find it correctly. Example, double array[5] = {1,2,3,4,5}; gsl_interp_accel *a = gsl_interp_accel_alloc(); unsigned index = gsl_interp_accel_find (a, array, 5, 5); //index = 3 This is because (as the docs state, http://www.gnu.org/software/gsl/ manual/html_node/Index-Look_002dup-and-Acceleration.html) the value x must fall into a bin which has the lower value LESS THAN EQUAL TO and an upper value LESS THAN x. How can I get a return index = 4? Cheers, Dan. _______________________________________________ Help-gsl mailing list [email protected] http://lists.gnu.org/mailman/listinfo/help-gsl _______________________________________________ Help-gsl mailing list [email protected] http://lists.gnu.org/mailman/listinfo/help-gsl
