[SciPy-User] interp1d results vs. MatLab interp1

Lynn Oliver raycores@gmail....
Mon Nov 21 10:29:36 CST 2011


I'm converting a MatLab program to Python, and I'm having problems understanding why scipy.interpolate.interp1d is giving different results than MatLab interp1.

In MatLab the usage is slightly different:
yi = interp1(x,Y,xi,'cubic')

While  in SciPy it's like this:
f = interp1d(x,Y,kind='cubic')
yi = f(xi)

For a trivial example the results are the same:
MatLab:
interp1([0 1 2 3 4], [0 1 2 3 4],[1.5 2.5 3.5],'cubic')
  1.5000 2.5000 3.5000

Python:
interp1d([1,2,3,4],[1,2,3,4],kind='cubic')([1.5,2.5,3.5])
array([ 1.5,  2.5,  3.5])

But for a real-world example they are not the same:
x =   0.0000e+000  2.1333e+001  3.2000e+001  1.6000e+004  2.1333e+004  2.3994e+004
Y =   -6   -6   20   20   -6   -6
xi =  0.00000 11.72161 23.44322 35.16484

Matlab:    -6.0000   -12.3303    -3.7384    22.7127

Python:    -6.  -15.63041012  -2.04908267  30.43054192

Any thoughts as to how I can get results that are consistent with MatLab?

Thanks-
Lynn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20111121/ae5be99f/attachment.html 


More information about the SciPy-User mailing list