如何求多项式方程的斜率?

2024-04-23 15:18:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在使用这段代码来寻找多项式方程及其对我的数据的导数。 我用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 dataHere 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]

Tags: the数据infornpresult曲线方程