PolynomialDegree
PolynomialDegree
PolynomialDegree[ expr ] determines the degree of a polynomial.
Usages
PolynomialDegree[ expr ]
PolynomialDegree[ expr ] returns the highest power of the variable in the polynomial expr. The polynomial must have one variable and must be written without brackets. In a script, wrap the command in Simplify.
| Example | in | out |
|---|---|---|
A polynomial in x. |
Simplify[ PolynomialDegree[ x^3+3x^2-4x ] ] |
3 |
| Any variable name can be used. | Simplify[ PolynomialDegree[ t^4-2t ] ] |
4 |
A constant has degree 0. |
Simplify[ PolynomialDegree[ 5 ] ] |
0 |
| A script variable. | p := x^4 - 2x |
d = 4 |
PolynomialDegree[ expr, var ]
PolynomialDegree[ expr, var ] returns the highest power of var in expr. Other variables are treated as coefficients.
| Example | in | out |
|---|---|---|
The degree in x. |
Simplify[ PolynomialDegree[ a x^2 + b x, x ] ] |
2 |
The degree in y. |
Simplify[ PolynomialDegree[ x^2 y^3 + x, y ] ] |
3 |
Details
- Without
Simplify, the command is not calculated: in a script,PolynomialDegree[ x^3+3x^2-4x ]stays unevaluated. - Brackets are not expanded:
PolynomialDegree[ (x+1)(x-1) ]is not calculated. Expand the polynomial first.
| Invalid input | Result |
|---|---|
Simplify[ PolynomialDegree[ x^2 y^3 + x ] ] |
Error: a polynomial with more than one variable needs the variable as second argument. |
Simplify[ PolynomialDegree[ 1/x ] ], Simplify[ PolynomialDegree[ Sin[x] ] ] |
Not calculated: the expression is not a polynomial. |
Warning
With a second argument, the degree is not always calculated when the polynomial has several other variables as coefficients. For example, PolynomialDegree[ a x^3+3b x^2-4c x+2d, x ] is not calculated. Check the result in the script debug information.