我目前正在使用这段代码来寻找多项式方程及其对我的数据的导数。 我用np.polyval来求导数,求出曲线上每个点的斜率
result = getDist(article_name, revilimit)
xAxis = [i for i in range(1,len(result)+1)]
xAxis = np.array(xAxis)
z = np.polyfit(xAxis, result, 10)
p = np.poly1d(z)
print('p = ')
print(p)
derivative = np.polyder(p)
print('derivative = ', end='')
print(np.polyder(p))
#x = np.polyval(derivative, result)
x = [(np.polyval(derivative,i)) for i in result]
Here is the curve I got with degree 10 for the data和 Here is the curve I got with degree 3 for the data
这里的问题是,当我替换导数方程中的x值时,得到的是所有正斜率(10阶曲线)或所有负斜率(3阶曲线)。 这是曲线方程,它是我得到的导数, Degree 3
我只想找到方程曲线的总斜率,它符合我的数据
编辑:如下面的注释所示,我输入的是Y轴值而不是X轴值 而不是
x = [(np.polyval(derivative,i)) for i in result]
我应该这么做的
x = [(np.polyval(derivative,i)) for i in xAxis]
目前没有回答
相关问题 更多 >
编程相关推荐