问题
已知:
sin(0.32)=0.314567
sin(0.34)=0.333487
sin(0.36)=0.352274
问:
用线性插值法及抛物线插值法(二次插值)求sin(0.3367)
代码
#-*-coding:utf-8 -*-
from scipy import interpolate #导入内插方式
from numpy import sin
x=[0.32,0.34,0.36]
y=[0.314567,0.333487,0.352274]
x3=0.3367
for kind in ["linear","quadratic"]:
f=interpolate.interp1d(x,y,kind=kind)
y3=f(x3)
print(kind,"插值法%.6f" %y3)
结果
linear 插值法0.330365
quadratic 插值法0.330374