Working with polynoms

Hi, everybody.
I wasn't successfull in finding the answer through the search. If the question was answered already, I'd be gratefull for a link.
The question itself:
if I've got an expression in brackets, I can expand it out of brackets, like so:
>> expand((s+4)*(s+0.5-0.2*i)*(s+0.5+0.2*i))
ans =s^3 + 5*s^2 + (429*s)/100 + 29/25
How can I make an opposite operation?
>> unexpand(s^3 + 5*s^2 + (429*s)/100 + 29/25)
ans =(s+4)*(s+0.5-0.2*i)*(s+0.5+0.2*i)
Or something like that.
I know, I can use the roots() function to calculate the expression myself, but I was wondering, if there is an easier way.
Thank you in advance for your answers.

 Respuesta aceptada

bym
bym el 14 de Abr. de 2012

2 votos

syms s
>> expand((s+4)*(s+0.5-0.2*i)*(s+0.5+0.2*i))
ans =
s^3 + 5*s^2 + (429*s)/100 + 29/25
>> factor(ans)
ans =
((s + 4)*(100*s^2 + 100*s + 29))/100
[edit]
ans =
s^3 + 5*s^2 + (429*s)/100 + 29/25
feval(symengine,'factor',ans,'C_')
ans =
(s + 4.0)*(s - 0.2*i + 0.5)*(0.2*i + s + 0.5)

3 comentarios

Boris
Boris el 15 de Abr. de 2012
That's a good way of rewriting the polynom, but it doesn't seem to work with complex roots. You still receive the 's' in the second power.
Is writing a code especially for this function the only solution?
bym
bym el 15 de Abr. de 2012
See my edit...
Boris
Boris el 18 de Abr. de 2012
Excellent solution! this is exactly, what I need.
Thanks a million! :)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Preguntada:

el 12 de Abr. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by