[SciPy-User] Forced derivative interpolation??

denis denis-bz-gg@t-online...
Mon Oct 12 06:25:36 CDT 2009


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


More information about the SciPy-User mailing list