Extract the degree of symbols

1 回表示 (過去 30 日間)
Mohammad Sh
Mohammad Sh 2021 年 4 月 21 日
回答済み: Sumukh 2024 年 9 月 5 日
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

回答 (1 件)

Sumukh
Sumukh 2024 年 9 月 5 日
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.

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by