Python立方样条插值表现奇怪

2024-05-19 23:25:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着用三次样条插值,但是插值在数据点周围波动很大。 我不知道怎么解决这个问题。任何建议都将不胜感激。你知道吗

enter image description here

TY = [90.3601709789,40.5189212844,20.3763456417,10.8899070251,6.19675122846,5.23402053792,6.05144428822,9.64276229024,24.1886072903,41.5725945652,171.923304843]
TX = [0.93984962406,0.90225563910,0.84586466165,0.75187969925,0.56390977444,0.37593984962,0.18796992481,0.07518796992,0.01879699248,0.00939849624,0.00187969925]

ipos = TX[0:6]
jpos = TY[0:6]

minpos = min(jpos)
maxpos = max(jpos)

ineg = TX[5:11]
jneg = TY[5:11]

minneg = min(jneg)
maxneg = max(jneg)

ypos1 = interp1d(jpos,ipos)
ypos2 = interp1d(jpos,ipos, kind='cubic')
xpos = np.linspace(minpos,maxpos,10000,endpoint=True)

yneg1 = interp1d(jneg,ineg)
yneg2 = interp1d(jneg,ineg, kind='cubic')
xneg = np.linspace(minneg,maxneg,10000,endpoint=True)

plt.figure('T')
plt.xscale('log')
plt.plot(TX,TY)
plt.plot(xpos,ypos2(xpos))
plt.plot(xneg,yneg2(xneg))

正反两部分是因为数据在中点改变了方向。你知道吗

enter image description here


Tags: 数据plotpltmin插值txtyipos
1条回答
网友
1楼 · 发布于 2024-05-19 23:25:16

由于连续二阶导数的要求,三次样条曲线容易发生振荡。为了避免这种情况,一种方法是使用C1连续样条。在scipy land中,查看PchpIntetpolator和/或Akima1DInterpolator

相关问题 更多 >