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

Anne Archibald peridot.faceted@gmail....
Fri Oct 16 02:40:09 CDT 2009

```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).

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
```