Cubic spline coefficients from Scipy Interpolate

45 Views Asked by At

I'm trying to get the coefficient of cubic spline poly from scipy interpolate Cubic Spline with the point (0,0),(1,1), (2,0). The coefficients I got are different from the values from site: https://tools.timodenk.com/cubic-spline-interpolation inserting the same points. I would like to know why. Thanks

from scipy.interpolate import CubicSpline

x=[0,1,2]
y=[0,1,0]

myCS=CubicSpline(x,y,axis=0,bc_type=((2,0),(2,0)))

print(myCS.c)

Expected: -0.5, 0, 1,5, 0 0.5,-3, 4.5, -1

1

There are 1 best solutions below

0
Thomas Beck On BEST ANSWER

We have to use the definition of the PPoly Class. This tells us that the coefficients outputted must first be first transformed using their formula to give the desired polynomial

For i=0 (aka the first polynomial) we subtract x[0] which is 0 so here they are the same.

For the second polynomial (i = 1) we have

0.5(x - 1.0)^3 - 1.5(x - 1.0)^2 + 0.0(x - 1.0)^1 + 1.0(x - 1.0)^0

which when expanded gives the same coefficients as the website