I have a vector consisting of taylor expansions of multiple variables, i.e. each element of the vector is a multivariate polynomial in X, X, etc. Not all the polynomials are of the same order, not all contain all the X[i]s.
I want to extract the coefficients of each component of the vector and store them in a Matrix.
I thought I had done it, but sadly the order of the coefficients is not what I expected.
Here is an example of a vector:
V := Vector([[a4*X^2+a1*X+a5*X*X+a2*X+a3*X^2],[(b1*X+b2*X)^2]]);
In general, I will need to 1) expand, 2) collect, 3) sort, and 4) extract coefficients, for each element of the Vector V.
Here's my best effort:
ExtractCoeffs := (V,X) -> Matrix([seq([coeffs(sort(collect(
[[a5, a2, a4, a1, a3],
[2*b1*b2, b2^2, b1^2, 0, 0]]
But I would like the coefficient on X first, on X second, on X*X third, on X^2 fourth, etc. I thought that would have been achieved by the sort options plex(X,X) and 'ascending.' I would even have expected it to be sorted that way simply by calling sort without any option.
What am I doing wrong?
As a supplementary question: anyway to write the above more succinctly and while keeping the size of the vector V and the number of variables X[i] unspecified?
I did try things like this, with the distributive tilde:
but no, that's not right...
Sadly, I didn't manage to adapt MatrixPolynomialAlgebra[Coeff] or PolynomialTools[CoefficientVector] to my purpose either...