首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在不反转系数的情况下利用poly1d多项式的导数

在不反转系数的情况下利用poly1d多项式的导数
EN

Stack Overflow用户
提问于 2018-03-17 01:12:25
回答 1查看 1.1K关注 0票数 1

我用poly1d和polyder来返回一个简单多项式的导数。

代码语言:javascript
复制
   3     2
1 x + 1 x + 1 x + 1

我看到这两个命令的简单组合并没有按照正确的顺序使用系数。

代码语言:javascript
复制
print(np.poly1d(P.polyder(c)))

我能用这样的衬垫吗?

代码语言:javascript
复制
print(np.poly1d(P.polyder(c)))

所以像上面这样的系数是正确的顺序吗?

代码语言:javascript
复制
Below is my code and output:

    import numpy as np
from numpy.polynomial import polynomial as P

print("")

c = (1, 1, 1, 1)

print("the array of coefficients for the polynomial")
print(c)

print("")

print("polynomial with coefficients and exponents")
print(np.poly1d(c))

print("")

print("array of coefficients of derivative of polynomial: lowest order coming first in the array")
d_c = P.polyder(c)
print(d_c)

print("")

print("reversing the array of coefficients for the derivative of the polynomial")
d_c = d_c[::-1]
print(d_c)

print("")

print("printing the derivative of the polynomial with exponents and coefficients")
print(np.poly1d(d_c))

print("")

print("printing the derivative of the polynomial without reversing the coefficient array after derivation")
print(np.poly1d(P.polyder(c)))

print("")

输出:

代码语言:javascript
复制
the array of coefficients for the polynomial
(1, 1, 1, 1)

polynomial with coefficients and exponents
   3     2
1 x + 1 x + 1 x + 1

array of coefficients of derivative of polynomial: lowest order coming first in the array
[ 1.  2.  3.]

reversing the array of coefficients for the derivative of the polynomial
[ 3.  2.  1.]

printing the derivative of the polynomial with exponents and coefficients
   2
3 x + 2 x + 1

printing the derivative of the polynomial without reversing the coefficient array after derivation
   2
1 x + 2 x + 3
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-17 17:47:16

对从deriv返回的对象使用np.poly1d方法

代码语言:javascript
复制
import numpy as np

p = np.poly1d([1, 3, 1, 0, 4])

print(p)
print(p.deriv(1))

有关可用方法的完整列表,请参见医生们

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49331545

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档