MatLab プログラムを Python に変換していますが、scipy.interpolate.interp2d(linear) が MatLab interp2(linear) とは異なる結果をもたらす理由を理解するのに問題があります。私は scipy.interpolate.rectbivariatespline が matlab interp2(cubic) と同じ結果を出していることを知っていますが、線形法では異なる結果が得られています。よろしくお願いします、Zeinab python:
from numpy import *
from scipy import interpolate
att=array([[ 239.044127,236.38616,231.891308,224.461261,212.628196,194.850501,170.332448,140.179075,107.822158,77.686597,52.989905,34.704514,22.112333,13.845297,8.577347,5.280345,3.238684,1.982192,1.211678,0.740152],[ 279.480169,276.646675,271.848543,263.89899,251.189969,231.976788,205.21918,171.832314,135.280008,100.344172,70.805784,48.14555,31.927007,20.837779,13.469048,8.656136,5.544346,3.544295,2.263191,1.444215],[ 326.756261,323.76423,318.690817,310.265908,296.745218,276.177018,247.251256,210.633036,169.730239,129.60991,94.611588,66.792291,46.097975,31.361771,21.150511,14.190114,9.491439,6.33744,4.227221,2.818012],[ 382.029446,378.906692, 373.604492, 364.77947, 350.562265, 328.799039, 297.892154, 258.195183, 212.95352, 167.411105, 126.421205, 92.660904,66.558802, 47.200839, 33.212749, 23.262033, 16.248519, 11.331774,7.895667, 5.49862 ],[ 446.652489, 443.440837, 437.980353, 428.871037, 414.139452, 391.447518,358.905095, 316.497136, 267.183987 ,216.237154, 168.925618, 128.548413,96.101273 , 71.039332 , 52.154139, 38.133744, 27.816052 , 20.261982,14.747643 , 10.729132],[ 522.206988, 518.966226, 513.448831 , 504.22346 , 489.246854 , 466.032868,432.414435 ,387.964004, 335.224713 , 279.303496 ,225.720556 , 178.335132,138.756323 ,106.917309 , 81.897894 , 62.513127 , 47.618665 , 36.2298, 27.545866 ,20.935121],[ 610.542076 ,607.354851 , 601.921297 , 592.815265, 577.975567 ,554.82951,520.979629, 475.5685 , 420.592603, 360.763363 , 301.610673 ,247.404216,200.34404 , 160.915237 , 128.604656 ,102.478559 , 81.519018 ,64.781346,51.450576 , 40.849466]])
att_r=logspace(0,log10(200),20)
att_m=linspace(4.5,7.5,7)
[r_grid,m_grid] = meshgrid(att_r,att_m)
rr=16
mm=4.6
att_cubic = interpolate.RectBivariateSpline(att_m,att_r,att)
Att_cubic = att_cubic(mm,rr)
print Att_cubic
att_linear = interpolate.interp2d(r_grid,m_grid,att,kind='linear')
Att_linear = att_linear(rr,mm)
print Att_linear
マトラブ:
att=[239.044127 236.386160 231.891308 224.461261 212.628196 194.850501 170.332448 140.179075 107.822158 77.686597 52.989905 34.704514 22.112333 13.845297 8.577347 5.280345 3.238684 1.982192 1.211678 0.740152
279.480169 276.646675 271.848543 263.898990 251.189969 231.976788 205.219180 171.832314 135.280008 100.344172 70.805784 48.145550 31.927007 20.837779 13.469048 8.656136 5.544346 3.544295 2.263191 1.444215
326.756261 323.764230 318.690817 310.265908 296.745218 276.177018 247.251256 210.633036 169.730239 129.609910 94.611588 66.792291 46.097975 31.361771 21.150511 14.190114 9.491439 6.337440 4.227221 2.818012
382.029446 378.906692 373.604492 364.779470 350.562265 328.799039 297.892154 258.195183 212.953520 167.411105 126.421205 92.660904 66.558802 47.200839 33.212749 23.262033 16.248519 11.331774 7.895667 5.498620
446.652489 443.440837 437.980353 428.871037 414.139452 391.447518 358.905095 316.497136 267.183987 216.237154 168.925618 128.548413 96.101273 71.039332 52.154139 38.133744 27.816052 20.261982 14.747643 10.729132
522.206988 518.966226 513.448831 504.223460 489.246854 466.032868 432.414435 387.964004 335.224713 279.303496 225.720556 178.335132 138.756323 106.917309 81.897894 62.513127 47.618665 36.229800 27.545866 20.935121
610.542076 607.354851 601.921297 592.815265 577.975567 554.829510 520.979629 475.568500 420.592603 360.763363 301.610673 247.404216 200.344040 160.915237 128.604656 102.478559 81.519018 64.781346 51.450576 40.849466];
r=logspace(0,log10(200),20);
m=[4.5:0.5:7.5]';
[r_grid,m_grid]=meshgrid(r,m);
rr=16;
mm=4.6;
att_cubic=interp2(r_grid,m_grid,att,rr,mm,'cubic')
att_linear=interp2(r_grid,m_grid,att,rr,mm)
出力 (matlab):
att_cubic =57.4565
att_linear =58.2270
出力 (パイソン):
Att_cubic=[[ 57.45649122]]
Att_linear=[ 56.13548995]