数学中的数值逼近问题
作者:互联网
import numpy as np
import pylab as pl
from scipy import interpolate
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
x = np.linspace(0, 2 * np.pi + np.pi / 4, 10)
y = np.sin(x)
x_new = np.linspace(0, 2 * np.pi + np.pi / 4, 100)
f_linear = interpolate.interp1d(x, y)
tck = interpolate.splrep(x, y)
y_bspline = interpolate.splev(x_new, tck) # 可视化
plt.xlabel(u'安培/A')
plt.ylabel(u'伏特/V')
plt.plot(x, y, "o", label=u"原始数据")
plt.plot(x_new, f_linear(x_new), label=u"线性插值")
plt.plot(x_new, y_bspline, label=u"B-spline插值")
pl.legend()
pl.show()
标签:plt,逼近,数值,数学,interpolate,import,np,new,pi 来源: https://blog.csdn.net/weixin_54718885/article/details/120219229