Q:

Convert coefficients of polynomials into a matrix

I have several sets of 5 polynomials of the form:
a0 = 0.00301472 - 0.0961879 beta - 0.860642 beta^2 - 4.73786 beta^3 - 
  0.00897697 z + 0.0389941 beta*z + 0.0131329 z^2 - 0.00552858 z^3

for a0,a1,...,a5, they form a vector A. My independent variables are beta and z.
I want a Matrix Q of the coefficients, such that when I multiply it by a vector of the form:
B={1, beta, z, beta z, beta^2, z^2, beta^3, z^3} 

like A=Q.B i recover my vector of polynomials.
How do I get the matrix Q in the easiest way? I have many sets, so it would take me hours. I have been trying some solutions with Coefficient[], but I am not fully satisfied.
Thanks!

A:

This seems to do the trick:
qmatrix = # /. {Plus -> List, Times[const_Real, x_] -> const, 
 n_Real -> n} & /@ vectorA

I've assumed that your coefficients are Real numbers, and it appears to pass the test:
vectorA == qmatrix.bvector

where you defined the b vector as:
B = {1, beta, z, beta z, beta^2, z^2, beta^3, z^3}

A:

r := RandomReal[{1, -1}, 8];
b = {be, z, be z, be^2, z^2, be^3, z^3, 1};
as = {a1, a2, a3, a4, a5} = Table[b.r, {5}];

u = Unique[ConstantArray[x, Length@b - 1]];

(*k is your matrix*)
k = (MonomialList[as /. Thread[Most@b -> u], u] /. Thread[u -> 1]);

(*Testing*)
k.b == as
(* True *)

