[SciPy-User] cubic spline interpolation - derivative value in an end point

Eric Carlson ecarlson@eng.ua....
Fri Nov 23 11:03:20 CST 2012


On 11/23/2012 4:52 AM, Paweł Kwaśniewski wrote:
> Hi,
>
> I don't really understand why you want to specify the derivative at 0.
> If, as you say, your function has a 0 derivative at 0, if you
> interpolate the function on the complete range where it is defined:
> [-1:1] with interpolate.splrep(), you can later evaluate it with splev()
> on whatever range you wish, like [0:1], and it should have the proper
> derivative.


Hello Paweł,

In fact, there are many cases where the derivative at the ends is 
available. For several years I used a (crudely numpy-wrapped) spline 
interpolation version from netlib, the same sources as those used for 
octave, in order to get clamped ends and (mostly) pchip. My wrapped 
versions performed much more slowly on evaluations than native scipy, 
though, so I quit using my wrapped versions once I found that pchip was 
available.

My ugly hack for getting a clamped condition on normal interpolating 
cubic splines has been to insert a point,

(x_near_end=x_end+small_dx,
  y_near_end=y_end+yprime_end*small_dx)

into my sorted data array at position 1 or -2. The results of this have 
pretty decent compared with my wrapped spline routine, and even though 
the spacing is not uniform, evaluation is still very fast.

Cheers,
Eric



More information about the SciPy-User mailing list