[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-gsl] Getting the index of a sorted vector entry closest to a c

From: Brian Gough
Subject: Re: [Help-gsl] Getting the index of a sorted vector entry closest to a certain value
Date: Fri, 11 Jun 2010 21:49:41 +0100
User-agent: Wanderlust/2.15.6 (Almost Unreal) Emacs/23.2 Mule/6.0 (HANACHIRUSATO)

At Tue, 8 Jun 2010 13:31:29 -0700,
Luke wrote:
> I have a gsl_vector whose values are evenly space from -M_PI to M_PI.
> I am using the GSL single dimensional root finding algorithm on a
> single equation which gives me a value that is in the range of [-M_PI,
> M_PI], but won't be exactly equal to any of the elements.  My goal is
> to find the index of the element in my gsl_vector which is closest to
> the solution from the root finding algorithm.  Here is an illustration
> of situation:
> v = {-1.0, -0.5, 0.0, 0.5, 1.0}
> x_star = 0.3
> Since the entry of v closest to x_star is 0.5, the index I would want
> to obtain is i = 3.
> I would imagine the function call to be something like:
> i = get_nearest_index(v, x_star);


See the Interpolation chapter of the manual in the section on "Index
Look-up and Acceleration"

Brian Gough

reply via email to

[Prev in Thread] Current Thread [Next in Thread]