Re: interpolation.hpp

Posted by Luigi Ballabio on
URL: http://quantlib.414.s1.nabble.com/interpolation-hpp-tp3515p3516.html

On 01/13/05 23:28:59, b.nonas wrote:

>
> I found a problem accessing the last (i.e. highest element) of a vector  
> by using 1D interpolation. The problem seems to be the xEnd-1 as the  
> upper bound for the std::upper_bound(xBegin,xEnd-1,value) function in  
> locate (Real x).
> upper_bound returns a pointer to [a.begin(),...,a.end) where the pointer
> to the last field is only returned for  value>=last element. By passing
> a.end()-1 to the function we are therefore effectively passing only the
> array
> [a[0],...,a.end()-2].

Bereshad,
        that is intentional. locate() returns an index j which is later  
used to interpolate between v[j] and v[j+1]. Therefore, j cannot be N-1 as  
in this case v[j+1] would be off the end of the vector.  When a value is  
asked close to the end of the range, locate() returns N-2 so that the data  
are interpolated between v[N-2] and v[N-1] and the correct value is  
returned.

Cheers,
        Luigi