# [SciPy-User] Forced derivative interpolation??

Anne Archibald peridot.faceted@gmail....
Mon Oct 12 10:36:30 CDT 2009

```Actually, there is code implementing pretty much what the OP requested
scipy.interpolate.KroghInterpolator. This only allows exact
specification of point and derivative information, not least-squares
fitting, and it doesn't necessarily support all the features that
splrep does, but the heavy lifting is done in compiled code.

Anne

2009/10/12 denis <denis-bz-gg@t-online.de>:
> An alternate component of array interpolate(), straight from Wikipedia
> (don't forget h !) --
>
> def spline_2p2s( t, p0, p1, m0, m1, h=1 ):
>    """ Hermite 2-point, 2-slope spline
>        see http://en.wikipedia.org/wiki/Cubic_Hermite_spline
>    """
>        # 0 -> p0,  1 -> p1,  1/2 -> (p0 + p1) / 2  -  (m1 - m0) / 8
>    try:
>        t2 = t*t
>        t3 = t2*t
>        return (
>          p0 * (2*t3 - 3*t2 + 1)
>        + p1 * (-2*t3 + 3*t2)
>        + m0 * h * (t3 - 2*t2 + t)
>        + m1 * h * (t3 - t2) )
>    except ValueError:
>        # shape mismatch: objects cannot be broadcast to a single
> shape
>        # i.e. points, t both vecs (is there a better way ?)
>        return [spline_2p2s( t, p0, p1, m0, m1, h ) for t in t.copy()]
>
> cheers
>  -- denis
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
```