问题描述
我有一个 X 和 Y 数据数组,我还有一个基于 X 值输出 Y 值的样条。
我需要得到一个将执行反向操作的样条,即输出超过 Y 值的 X 值。
(interpolate.splrep(y,x,s=0)
不建议)
def f(x):
return math.sin(x)
def compare_func(func,a,b,eps):
x_for_plot = list(np.arange(a,eps / 10))
x = list(np.arange(a,eps))
y_for_plot = [func(i) for i in x_for_plot]
y = [func(i) for i in x]
plt.plot(x_for_plot,y_for_plot,label='Orig')
plt.scatter(x,y,label='Points',color='blue')
spline = interpolate.splrep(x,s=0)
y_interpolated = interpolate.splev(x_for_plot,spline,der=0)
spline_inv = ???
x_calc = interpolate.splev(y_interpolated,spline_inv,der=0)
print(x_calc)
#x_calc and x_for_plot must be equal
plt.plot(x_for_plot,y_interpolated,label='Interpolated')
plt.xlabel('X')
plt.ylabel('Y')
plt.legend()
plt.show()
compare_func(f,-3,3,0.5)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)