努比。polyval(p,x) 方法以特定的值计算多项式。
null
如果 “不” 是多项式“p”的长度,则此函数返回值
Parameters :
p: [array_-like或poly1D]多项式系数按幂的降序给出。如果第二个参数(root)设置为True,那么数组值就是多项式方程的根。 例如: poly1d(3,2,6)=3x 2. +2x+6x: [array_like或poly1D]一个数字,一组数字,用于计算“p”。
Return:
多项式的估值。
代码: 解释polyval()的Python代码
# Python code explaining # numpy.polyval() # importing libraries import numpy as np import pandas as pd # Constructing polynomial p1 = np.poly1d([ 1 , 2 ]) p2 = np.poly1d([ 4 , 9 , 5 , 4 ]) print ( "P1 : " , p1) print ( " p2 : " , p2) |
# Solve for x = 2 print ( "p1 at x = 2 : " , p1( 2 )) print ( "p2 at x = 2 : " , p2( 2 )) |
a = np.polyval([ 1 , 2 ], 2 ) b = np.polyval([ 4 , 9 , 5 , 4 ], 2 ) print ( "Using polyval" ) print ( "p1 at x = 2 : " , a) print ( "p2 at x = 2 : " , b) c = np.polyval(np.poly1d([ 4 , 9 , 5 , 4 ]), np.poly1d( 2 )) print ( "c : " , c) |
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END