What algorithm used in interp1d function in scipy.interpolate
Question: So i was writing a python program for my numerical course, and I had to code a
cubic spline program. So i implement the formula for cubic spline given in
books like [Numerical methods by Chapra and
canale](http://rads.stackoverflow.com/amzn/click/0073401064) and [Numerical
mathematics by chenny and
kincaid](http://rads.stackoverflow.com/amzn/click/1133103715).

so my data is

    
    
    x=[1.0,3.0,4.0,7.0]
    y=[1.5,4.5,9.0,25.5]
    

Using this data and applying cubic spline I get for `x=1.5` ,
`y=1.79122340426`

While using this same data but using the scipy function gives:

    
    
      >>> scipy.interpolate.interp1d(x, y, kind='cubic')(1.5)
    array(1.265624999999932)
    

So, why is that difference in result? It is obvious that they are not using
the same formula. What is the cubic spline formula used in that scipy
function? Is it a natural cubic spline formula or something improved? Note:
The value 1.2656 is more acurate.


Answer: EDIT: @ev-br in the comments for this answer provided an important correction
to my answer. In fact interp1D spline is not FITPACK based. Check the comments
for the link provided by @ev-br.

The Scipy functions for curve fitting are based on FITPACK. Try seeing the
documentation on the functions you are using and you'll be able to see a
"References" chapter where something like this will appear:

    
    
    Notes
    -----
    See splev for evaluation of the spline and its derivatives. Uses the
    FORTRAN routine curfit from FITPACK.
    If provided, knots `t` must satisfy the Schoenberg-Whitney conditions,
    i.e., there must be a subset of data points ``x[j]`` such that
    ``t[j] < x[j] < t[j+k+1]``, for ``j=0, 1,...,n-k-2``.
    References
    ----------
    Based on algorithms described in [1]_, [2]_, [3]_, and [4]_:
    .. [1] P. Dierckx, "An algorithm for smoothing, differentiation and
       integration of experimental data using spline functions",
       J.Comp.Appl.Maths 1 (1975) 165-184.
    .. [2] P. Dierckx, "A fast algorithm for smoothing data on a rectangular
       grid while using spline functions", SIAM J.Numer.Anal. 19 (1982)
       1286-1304.
    .. [3] P. Dierckx, "An improved algorithm for curve fitting with spline
       functions", report tw54, Dept. Computer Science,K.U. Leuven, 1981.
    .. [4] P. Dierckx, "Curve and surface fitting with splines", Monographs on
       Numerical Analysis, Oxford University Press, 1993.
    

These references in particular where taken from the source of
[fitpack.py](https://github.com/scipy/scipy/blob/master/scipy/interpolate/fitpack.py)
on the function "splrep". If you need to do a very thorough comparison between
your algorithm and the spline from interp1D just go to the docs:

[scipy.interpolate.interp1d](http://docs.scipy.org/doc/scipy-0.16.0/reference/generated/scipy.interpolate.interp1d.html#scipy-
interpolate-interp1d)

And you'll see a link called
[[source]](https://github.com/scipy/scipy/blob/v0.16.1/scipy/interpolate/interpolate.py#L306)
right after the definition of the name of the function (so:
scipy.interpolate.interp1D [source]). Remember that there's a lot of routine
handlers on these functions so be patient while navigating the source.

