在不反转系数的情况下使用 poly1d polyder 对多项式求导
taking derivative of a polynomial using poly1d polyder without reversing the coefficients
我正在使用 poly1d 和 polyder 来 return 简单多项式的导数。
3 2
1 x + 1 x + 1 x + 1
我发现这两个命令的简单组合并没有以正确的顺序使用系数。
print(np.poly1d(P.polyder(c)))
有没有一个我可以像这样使用的衬垫
print(np.poly1d(P.polyder(c)))
以便上面的系数顺序正确?
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("")
输出:
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
对从 np.poly1d
返回的对象使用 deriv
方法:
import numpy as np
p = np.poly1d([1, 3, 1, 0, 4])
print(p)
print(p.deriv(1))
有关可用方法的完整列表,请参阅 the docs。
我正在使用 poly1d 和 polyder 来 return 简单多项式的导数。
3 2
1 x + 1 x + 1 x + 1
我发现这两个命令的简单组合并没有以正确的顺序使用系数。
print(np.poly1d(P.polyder(c)))
有没有一个我可以像这样使用的衬垫
print(np.poly1d(P.polyder(c)))
以便上面的系数顺序正确?
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("")
输出:
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
对从 np.poly1d
返回的对象使用 deriv
方法:
import numpy as np
p = np.poly1d([1, 3, 1, 0, 4])
print(p)
print(p.deriv(1))
有关可用方法的完整列表,请参阅 the docs。