LMO*_*LMO 10 python matlab interpolation scipy
我正在将MatLab程序转换为Python,我在理解为什么scipy.interpolate.interp1d提供的结果与MatLab interp1不同时遇到了问题.
在MatLab中,使用情况略有不同:
yi = interp1(x,Y,xi,'cubic')
Run Code Online (Sandbox Code Playgroud)
SciPy的:
f = interp1d(x,Y,kind='cubic')
yi = f(xi)
Run Code Online (Sandbox Code Playgroud)
对于一个简单的例子,结果是相同的: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
Run Code Online (Sandbox Code Playgroud)
蟒蛇:
interp1d([1,2,3,4],[1,2,3,4],kind='cubic')([1.5,2.5,3.5])
array([ 1.5, 2.5, 3.5])
Run Code Online (Sandbox Code Playgroud)
但对于现实世界的例子,它们并不相同:
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... (2048 data points)
Run Code Online (Sandbox Code Playgroud)
Matlab的:
-6.0000e+000
-1.2330e+001
-3.7384e+000
...
7.0235e+000
7.0028e+000
6.9821e+000
Run Code Online (Sandbox Code Playgroud)
SciPy的:
array([[ -6.00000000e+00],
[ -1.56304101e+01],
[ -2.04908267e+00],
...,
[ 1.64475576e+05],
[ 8.28360759e+04],
[ -5.99999999e+00]])
Run Code Online (Sandbox Code Playgroud)
有关如何获得与MatLab一致的结果的任何想法?
编辑:我知道立方插值算法的实现存在一定的自由度,这可能解释了我所看到的差异.似乎我转换的原始MatLab程序应该使用线性插值,所以问题可能没有实际意义.
| 归档时间: |
|
| 查看次数: |
5070 次 |
| 最近记录: |