How to find degree of polynomial in Matlab?

19 ビュー (過去 30 日間)
Sohail
Sohail 2013 年 12 月 30 日
コメント済み: Sohail 2013 年 12 月 30 日
Dear All, Good day! I am trying to find the degree of polynomial in MATLAB. I know it is possible in MuPAD by using degree(p). But couldn't find a way by using editor. Kindly help me on this. Thanks
  2 件のコメント
Walter Roberson
Walter Roberson 2013 年 12 月 30 日
How is the polynomial represented ?
Sohail
Sohail 2013 年 12 月 30 日
Actually I want to compare the nominator and denominator degree and depending on that I have to take some decision. Here is the small code that shows the z(p) Rational polynomial (RP). I put limit on that to get new RP. Now I want to compare the degree of num and den of znew(p). How I can extract the degree?
clc;
close all;
clear all;
syms p
z(p)=(2*p^4+5*p^2+1)/(p^3+p);
a=limit(z(p)/p, p, inf);
z1(p)=z(p)-a*p;
Znew=simplify(z1(p));
[num,den] = numden(Znew);

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2013 年 12 月 30 日
In the case you use, where you are working with ratios of symbolic polynomials, then
degree_num = length(coeffs(num,p)) - 1;
degree_den = length(coeffs(den,p)) - 1;
You can also simplify (at least logically) the taking of the limit:
[n, d] = numden(z(p));
coeffn = coeffs(n,p);
coeffd = coeffs(d,p);
lenn = length(coeffn);
lend = length(coeffd);
if lenn > lend + 1
error('limit would have been infinite')
elseif lenn <= lend
error('limit would have been zero');
else
a = coeffn(end);
end
If you are sure that neither of the two exception cases can occur, then
t = coeff(numden(z(p)));
a = t(end);
  3 件のコメント
Walter Roberson
Walter Roberson 2013 年 12 月 30 日
You could use sym2poly() . Again length() - 1 for degree, but the first entry of the matrix instead of the last entry for the highest coefficient.
Sohail
Sohail 2013 年 12 月 30 日
Thanks alot mate. Have a good day. :)

サインインしてコメントする。

その他の回答 (2 件)

The Matlab Spot
The Matlab Spot 2013 年 12 月 30 日
編集済み: The Matlab Spot 2013 年 12 月 30 日
See if polyval helps
  1 件のコメント
Sohail
Sohail 2013 年 12 月 30 日
We cannot find degree of poly. using polyval().

サインインしてコメントする。


Roger Stafford
Roger Stafford 2013 年 12 月 30 日
Suppose you evaluate your polynomial, P(x), at a large number of equally-spaced values of x. Then if diff(P,n) exhibits a non-zero constant value (except of course for small round-off errors,) you can conclude that P has degree n. Moreover, that constant value is indicative of the coefficient of the highest degree term.
I would think however, that an inspection of whatever process is creating your polynomial should more easily tell you its degree.

カテゴリ

Help Center および File ExchangePolynomials についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by