Borrar filtros
Borrar filtros

How to get all the coefficients of a polynomial?

8 visualizaciones (últimos 30 días)
DmArcher
DmArcher el 26 de Abr. de 2017
Comentada: Walter Roberson el 28 de Abr. de 2017
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 comentarios
Walter Roberson
Walter Roberson el 26 de Abr. de 2017
Which release are you using?
DmArcher
DmArcher el 27 de Abr. de 2017
I'm using 2015b

Iniciar sesión para comentar.

Respuestas (3)

John D'Errico
John D'Errico el 27 de Abr. de 2017
Editada: John D'Errico el 27 de Abr. de 2017
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 comentarios
DmArcher
DmArcher el 28 de Abr. de 2017
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 el 28 de Abr. de 2017
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.

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 27 de Abr. de 2017
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 el 26 de Abr. de 2017
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.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by