Getting the Polynomial coefficients
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello,
I am trying to identify if a given function is polynomial or not and if it is polynomial what the coefficients are. For example;
sym F x
F= 5*x^5+cos(x)*x^2+1 % This is not polynomial because of cos(x) and I want to identify that.
[c,t] = coeffs(F);
PolyCoef = sym2poly(F);
c =
[ 5, 1, 1] % no cos(x) is given in here
>> t
t =
[ [x^5, 1], [x^2, x], [1, 1]] % no cos (x) is given in here
and sym2poly will give error. I am okay with the error as long as it does not stop the program and tell me that input function is not polynomial.
Thanks for the help.
댓글 수: 0
채택된 답변
Mohammad Abouali
2015년 4월 26일
Part I
You are using SYM() while using SYMS style of command. They are different. So change sym F x to syms F X or if you insist on using sym() then you need to use it properly such as F=sym('F')'
Part II
You can use that error to determine both the coefficient and if it was polynomial or not. You can use try/catch as follows:
try
PolyCoef = sym2poly(F);
catch
disp('that was not a polynomial')
PolyCoef=[];
end
In this case the program is not halted. If the statement(s) between catch and end (catch block) is only executed if, the statements between try and catch (try block), i.e. PolyCoef = sym2poly(F) in this case, produces any error. Refer to try/catch for further info on that.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Polynomials에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!