标签:python TE class 式表 out 数组 fill 对象 val
多项式函数是变量的整数次冥与系数的乘积之和,可以用下面的公式表示:
如果f(x) = 2x2 +x +1
a= np.array([2,1,1])
p = np.poly1d(a)
p
Out[78]: poly1d([2, 1, 1]) #等同于2*x2 + 1* x1 +1*x0 = 2x2 + x +1
print(p)
2 x2 + 1 x + 1
带入值:
p([1,2,3])
Out[80]: array([ 4, 11, 22])
对poly1d( )对象进行加减乘除运算,相当于对应多项式函数进行计算,如:
多项式对象的deriv( )和integ( )方法分别用于计算多项式函数的微分和积分,如:
p.deriv() #微分
Out[84]: poly1d([4, 1])
p.integ() #积分
Out[85]: poly1d([ 0.66666667, 0.5 , 1. , 0. ])
多项式函数的根可以用roots( )计算:
np.roots(p)
Out[86]: array([-0.25+0.66143783j, -0.25-0.66143783j])
除了使用多项式对象外,还可以直接使用Numpy提供的多项式函数对多项式系数的数组进行运算,主要函数包括:np.poly, np.polyadd, np.polydiv, np.polyint, np.polysub, np.poly1d, np.polyder, np.polyfit, np.polymul, np.polyval等。
标签:python TE class 式表 out 数组 fill 对象 val
原文地址:https://www.cnblogs.com/fengguozhuying/p/9167576.html