Trying to sort the coefficients of the polynomial (z-a)(z-b)(z-c)...(z-n) into a vector
Posted
by
pajamas
on Programmers
See other posts from Programmers
or by pajamas
Published on 2012-05-06T23:09:22Z
Indexed on
2013/10/29
16:12 UTC
Read the original article
Hit count: 162
algorithms
|matlab
So I have a factored polynomial of the form (z-a)(z-b)(z-c)...(z-n) for n an even positive integer. Thus the coefficient of z^k for 0 <= k < n will be the sum of all distinct n-k element products taken from the set {a,b,...,n} multiplied by (-1)^k, I hope that makes sense, please ask if you need more clarification.
I'm trying to put these coefficients into a row vector with the first column containing the constant coefficient (which would be abc...n) and the last column containing the coefficient for z^n (which would be 1).
I imagine there is a way to brute force this with a ton of nested loops, but I'm hoping there is a more efficient way. This is being done in Matlab (which I'm not that familiar with) and I know Matlab has a ton of algorithms and functions, so maybe its got something I can use. Can anyone think of a way to do this?
Example: (z-1)(z-2)(z-3) = z^3 - (1 + 2 + 3)z^2 + (1*2 + 1*3 + 2*3)z - 1*2*3 = z^3 - 6z^2 + 11z - 6. Note that this example is n=3 odd, but n=4 would have taken too long to do by hand.
Edit: Let me know if you think this would be better posted at TCS or Math Stack Exchange.
© Programmers or respective owner