Extract the degree of symbols

1 view (last 30 days)
Mohammad Sh
Mohammad Sh on 21 Apr 2021
Answered: Sumukh on 5 Sep 2024
Hi How can I extract the degree of symbols from an equation, for example my equation is ' eq=x^2/y^3 ' and I want and command to show me the degree of y and answer me the -3

Answers (1)

Sumukh
Sumukh on 5 Sep 2024
Hi Mohammad,
The degree of a variable in a polynomial is always a non-negative whole number. The “polynomialDegree(p,vars)” function can be used to obtain the power of a variable(s) in the “vars” input argument, in a polynomial “p”. You can refer to the following documentation to know more about the function:
The given equation has variables with negative powers, and “polynomialDegree” returns an error for such equations as they are not polynomials.
A workaround is to first use the function “numden” to separate out numerator and denominator polynomials. The “polynomialDegree” function can then be used to obtain the power of the variable “y” in the numerator (0) and denominator (3). You can refer to the following documentation to know more about the “numden” function:
You can run the following code to obtain the power of “y” in the given equation:
% Define symbolic variables
syms x y
% Define the equation
eq = x^2 / y^3;
% Simplify the equation to separate terms
[n, d] = numden(eq);
% Calculate the degree of y in the numerator and denominator
degree_y_numerator = polynomialDegree(n, y);
degree_y_denominator = polynomialDegree(d, y);
% The degree of y in the equation is the difference
degree_y = degree_y_numerator - degree_y_denominator;
% Display the result
disp(degree_y);
-3
I hope this resolves your query.

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!