The degree of function is unknown

1 view (last 30 days)
Mohamed Mahmoud
Mohamed Mahmoud on 24 Oct 2020
Answered: Walter Roberson on 25 Oct 2020
syns Q, x, a
Q=5*x^(2+a)
polynomialDegree(Q)
I want the answer to be 2+a

Answers (2)

VBBV
VBBV on 25 Oct 2020
Edited: Walter Roberson on 25 Oct 2020
Do you mean this expression ?
syms x a
Q=5*x^2 + a;
polynomialDegree(Q)
ans =
2
  1 Comment
Walter Roberson
Walter Roberson on 25 Oct 2020
No, the user stated clearly they had x^(2+a) and wanted (2+a) as the answer.

Sign in to comment.


Walter Roberson
Walter Roberson on 25 Oct 2020
This is proving to be a challenge to implement in the general case.
So far I have code that automatically reduces multiples of x to remove the multiplier, and I have code that can extract the power coefficient for x^power . However, I have not figured out yet how to handle sum of polynomial terms, and I have not figured out yet how to handle situations such as 1/(x^2+3) .
Oh yes, and my code at the moment is only valid for variable x . The polynomialDegree function by default works over all variables, so if you need to replicate that then you would need to figure out what you meant by the polynomial degree of Q with respect to variable a and not just variable x
The polynomial degree with respect to a given variable is the maximum degree for the terms, and that is not conceptually difficult for constant powers, but suppose you had
R = 5*x^(2+a) - 3*x^(2*a)
then what is the polynomial degree with respect to x? It would be max(2+a, 2*a) and you would have to leave it expressed as a maximum because 2+a > 2*a for a < 2. But symbolic toolbox does not actually have a delayed max function: you have to express max(2+a,2*a) by piecewise(2+a <= 2*a, 2+a, 2*a) and that quickly gets pretty messy as soon as you have three terms.
And what should the result be when a < -2 ? Or in the case of x^(2*a) if a < 0 ? What should be the degree for
x^2 + x^(-2)
?

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!