Coefficients of maximums of polynomials

Is there a built-in function at the maxima to get a list with its coefficients from a polynomial function? And to get a polynomial degree?

The most similar function I found is args , but it also returns a variable along with a coefficient. I could accept this, even more when using length along with args will return a power. The problem is that args does not work with polynomials of degree zero.

Is there any other feature that is better suited for these purposes? Thanks in advance.

+5
source share
1 answer

To calculate the degree of a polynomial in a single variable, you can use the hipow function.

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

For a polynomial with more than one variable, you can map hipow to the variables returned by the listofvars function, and then take the maximum of the resulting list.

 (%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 

The coeff function returns the coefficient x^n given by coeff(p,x,n) , therefore, to generate a list of polynomial coefficients from a single variable, we can iterate over powers of x, preserving the coefficients to the list.

 (%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] 

And to generate a list of polynomial coefficients in more than one variable, draw coeffs1 over listofvars .

 (%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]] 
+7
source

Source: https://habr.com/ru/post/1244617/


All Articles