필터 지우기
필터 지우기

How to get all the coefficients of a polynomial?

조회 수: 8 (최근 30일)
DmArcher
DmArcher 2017년 4월 26일
댓글: Walter Roberson 2017년 4월 28일
I tried the sample from MATLAB documentation but I get something else which is different from the result in the documentation. Does anyone know where I did it wrong? The result in the documentation is be [3,0,0] which returns all the coefficients all the way from 0 degree. But I get 3*x^2 which makes no sense.
  댓글 수: 2
Walter Roberson
Walter Roberson 2017년 4월 26일
Which release are you using?
DmArcher
DmArcher 2017년 4월 27일
I'm using 2015b

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

답변 (3개)

John D'Errico
John D'Errico 2017년 4월 27일
편집: John D'Errico 2017년 4월 27일
One problem with text is knowing that you are writing the number 1, versus the lower case LETTER l. Some fonts make this more or less obvious than others of course.
syms x
coeffs(3*x^2,'all')
ans =
[ 3, 0, 0]
In the PICTURE you posted, you clearly wrote 'A11', as opposed to 'All'. In general, it is a silly idea to post a picture of text, because then we cannot copy the text and try to use it. Just paste in the TEXT! In this case, if you had put the text itself in, then I could have shown exactly what you did incorrectly even more conclusively.
In the first case above, those were ONES, not lower case L's. There is a difference.
If instead, I try it using numeric ones in there:
coeffs(3*x^2,'a11')
ans =
3*x^2
then I get the same wrong answer that you got.
  댓글 수: 3
DmArcher
DmArcher 2017년 4월 28일
Thank you so much. But if I have an other symbolic variable as the coefficient and I want to show all the coefficients. What should I do?
syms f1 f2 z
a = (f1-f2)*z^2
coeffes(a,z,'all')
This will report error that I have too many inputs.
Walter Roberson
Walter Roberson 2017년 4월 28일
As I indicated, R2015b does not support the 'all' argument. You need to either upgrade to at least R2016a, or use the methods I outlined in my Answer.

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


Walter Roberson
Walter Roberson 2017년 4월 27일
In R2015b, there was no 'all' option; http://www.mathworks.com/help/releases/R2015b/symbolic/coeffs.html; that was added in R2016a.
If you have only a single variable, then I suggest you use sym2poly instead:
>> sym2poly(3*x^2)
ans =
3 0 0
If you have multiple variables, then use the two-output form of coeffs, and then match through the items in the second output looking to see which powers are missing in order to know to assign the coefficient 0 to those.

Nhan Nguyen
Nhan Nguyen 2017년 4월 26일
I don't know which version of Matlab that your book was based on.
I'm using Matlab 2015b and I can't find the option 'All' in description of the function "coeffs". To extract the coefficients of the polynomial, I just need to type
syms x
coeffs(3*x^2)
and the output is 3.
I think you should check if your Matlab version fit with those in the book.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by