# [SciPy-User] scipy.interpolate.KroghInterpolator: output confusion.

Antonio Valentino antonio.valentino@tiscali...
Fri Oct 16 04:18:57 CDT 2009

```Hi Anne,

Il giorno Fri, 16 Oct 2009 03:40:09 -0400
Anne Archibald <peridot.faceted@gmail.com> ha scritto:

> 2009/10/16 Marco Nicoletti <nicoletti@consorzio-innova.it>:
> > Dear all,
> >
> > I have found something that loks like a bug (or at least a
> > confusing staff) in the output of KroghIntepolator class.
> >
> > The problem is the following:
> >
> > case 1
> > from scipy import interpolate
> > import numpy as np
> > xi = [2, 3, 4]
> > yi = [10,13,15]
> > yi_der = [1, 2, 2.5]
> > Y = np.asarray([yi, yi_der]).transpose()
> > krogh = interpolate.KroghInterpolator(xi, Y)
> > print krogh(2.3)
> >>> [ 11.005    1.3525]
> > Evaluating one point 2.3, it returns a 1-D array with array([value,
> > derivative value]).
>
> This is not what the interpolator is doing. You have constructed an
> interpolator that takes no derivative information, but produces vector
> values. To specify derivative information, you must repeat the x value
> in question. So to do the interpolation you were intending, you should
> do:
>
> krogh =
> interpolate.KroghInterpolator([2,2,3,3,4,4],[10,1,13,2,15,2.5])
>
> Calling this object then yields scalars. If you want derivatives, you
> can ask for as many as you want with krogh.derivatives, which will
> provide you with an array, or krogh.derivative, which will provide you
> with a particular one.
>
> This way of specifying derivatives is a little peculiar, but it is
> what the underlying algorithm needs, and it also allows you to have
> different numbers of derivatives at each point (as with the example in
> the docstring).

the example seems to conflicts with the rest of the docstring that
clearly states:

"""
Parameters
----------
xi : array-like, length N
known x-coordinates
yi : array-like, N by R
known y-coordinates, interpreted as vectors of length R,
or scalars if R=1
"""

xi: N
yi: NxR with R = number of derivatives available at each point.

Is it a bug in the documentation?

I think that the one described in the docstring is a more handy
interface with respect to the one of the example.

> This odd calling convention is actually explained in the docstring,
> although it's not emphasized as much as it might be.
>
> I should also suggest you be careful with very high-degree
> polynomials: if you're using them to fit data with noise, you are
> liable to get high-degree terms that thrash wildly around trying to
> match your noise. This is one reason splines - piecewise low-degree
> polynomials - are so popular.
>
>
> Anne
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user

--
Antonio Valentino
```