2016-03-07 106 views
5

是否有一個內置函數在最大值從一個多項式函數獲得一個列表及其係數?並獲得多項式的程度?多項式係數最大值

我發現的最相似的功能是args,但它也會返回變量和係數。我本可以接受這一點,當使用lengthargs將返回學位時更多。問題是args不適用於零度多項式。

是否還有另一個功能可以更好地適應這些目的?提前致謝。

回答

7

要計算一個變量中多項式的次數,可以使用hipow函數。

(%i) p1 : 3*x^5 + x^2 + 1$ 
(%i) hipow(p1,x); 
(%o)        5 

對於具有多個變量的多項式,可以映射hipow在由listofvars函數返回的變量,然後取最大值結果列表中。

(%i) p2 : 4*y^8 - 3*x^5 + x^2 + 1$ 
(%i) degree(p) := if integerp(p) then 0 else 
      lmax(map (lambda([u], hipow(p,u)),listofvars(p)))$ 
(%i) degree(p1); 
(%o)        5 
(%i) degree(p2); 
(%o)        8 
(%i) degree(1); 
(%o)        0 

coeff函數返回給coeff(p,x,n),所以要產生一個變量的多項式的係數列表的x^n係數,我們可以通過x的權力迭代,保存係數的列表。

(%i) coeffs1(p,x) := block([l], l : [], 
         for i from 0 thru hipow(p,x)  
          do (l : cons(coeff(p,x,i),l)), l)$ 
(%i) coeffs1(p1,x); 
(%o)      [3, 0, 0, 1, 0, 1] 

,並在超過一個變量,地圖coeffs1listofvars生成多項式的係數的列表。

(%i) coeffs(p) := map(lambda([u], coeffs1(p, u)), listofvars(p))$ 
(%i) coeffs(p2); 
(%o) [[- 3, 0, 0, 1, 0, 4 y^8 + 1], 
     [4, 0, 0, 0, 0, 0, 0, 0, - 3 x^5 + x^2 + 1]] 
+0

你的學位只是max-hipow,但不是max-monomial degree。後者可以例如給出度(x^2 * y-x)= 3。 –