MATLAB: Expansion of a polynomial (Best way)

computational complexityexpansionpolynomial

Hi, I have a polynomial of the form : (1+x^a1)*(1+x^a2)*…*(1+x^an), and I want to expand it (compute its coefficients). Which is the best way (low computational complexity) of doing this in Matlab?
I hope it is clear. Thanks for your help.
Best regards. H.

Best Answer

Let a be a row vector consisting of your exponents, a1, a2, ..., an. Then try this:
A = cumsum([0,a])+1;
a1 = a + 1;
C = [1,zeros(1,A(size(A,2))-1)];
for k = 1:size(a,2)
C(a1(k):A(k+1)) = C(a1(k):A(k+1)) + C(1:A(k));
end
The C row vector will have the coefficients of the powers of x for your product:
C(1)+C(2)*x+C(3)*x^2+C(4)*x^3+C(5)*x^4+...
Related Question