我不确定如何根据数据集将值分配给创建的多项式。我希望为多项式中的x赋一个变化的值Hi
。需要将此多项式转换为基于此Hi
值的值,并将其插入函数hip1
中。
如果我将生成的多项式直接插入hip1
中,该问题就解决了,但是我想将其作为定义的函数,以防万一我想更改数据集,因此不需要输入新的多项式再次变成hip1
。
xs = [6, 5, 4, 3, 2, 1, 0]
ys = [11700, 9700, 6700, 4500, 3200, 1800, 0]
def poly(Hi):
return np.poly1d(np.polyfit(xs, ys, deg=5))
def hip1(Hi,g,e,d,dt):
return Hi -((np.pi*d**2)*np.sqrt(2*g*(Hi + e))*dt) / (4*poly(Hi))