views:

145

answers:

1

Hi!

From scipy I am using the interpolate.splrep and interpolate.splev functions to get interpolate my data set. Unsurprisingly, this does not work very well if I try to get an interpolated value near the edges of the data set.

I came up with a workaround (extending the data set by two additional entries which have the same value as the last "regular" entry of the data set; which seems to work), but I am wondering if either I shoult use another interpolation function, or if there is a common way to deal with this.

Thanks in advance!

A: 

I'm not familliar with scipy unfortunally, but maybe this would help:

I presume, these are polynomial spline functions, therefore you can actually interpolate your dataset near the edges with actual polynomes. It is easy.

Let's presume, we have a dataset of points like (xi,yi), i=1..n . From splerp function we can find a first derivative (finite difference will do actually) in points '2' (df_second') and 'n-1' (df_before_last). Then we need two system of linear equations:

a1*x1^2 + b1*x1 + c1 = y1
a1*x2^2 + b1*x2 + c1 = y2
2*a1*x2 + b1 = df_second

and

a2*xn^2 + b2*xn + c2 = yn
a2*x(n-1)^2 + b2*x(n-1) + c2 = y(n-1)
2*a2*x(n-1) + b2 = df_before_last

Solving this equations you'll get two polymones: a1*x^2 + b1*x + c1 and a2*x^2 + b2*x + c2 which will be interpolating and smothly accessed to the spline funcion.

Actually, you may raise polynoms degree and set interpolant graphics curvature and angle in first and last point by just putting additional equations in a system.

akalenuk