필터 지우기
필터 지우기

Getting the Polynomial coefficients

조회 수: 2 (최근 30일)
Kamuran
Kamuran 2015년 4월 26일
편집: Kamuran 2015년 4월 26일
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.

채택된 답변

Mohammad Abouali
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.
  댓글 수: 1
Kamuran
Kamuran 2015년 4월 26일
편집: Kamuran 2015년 4월 26일
Thanks, that is what I was looking for

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Number Theory에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by