# [Maxima] Getting multivariate polynomial coefficents

sen1 at math.msu.edu sen1 at math.msu.edu
Mon Jan 15 11:54:17 CST 2007

```I don't know if there are routines to deal with homogeneous
polynomials, but, for the problem you mentioned, you can write your
own routine which makes successive use of the function
coeff

For instance,

(%i12) p1: expand((x1 + x2)^2 +x2);
2                    2
(%o12)                     x2  + 2 x1 x2 + x2 + x1
(%i13) coeff(p1,x2^2);
(%o13)                                 1
(%i14) coeff(p1,x2);
(%o14)                             2 x1 + 1
(%i15) coeff( coeff(p1,x2),x1);
(%o15)                                 2

(%i10) p1: expand((x1 + x2)^2 +x2);
2                    2
(%o10)                     x2  + 2 x1 x2 + x2 + x1
(%i11) coeff( coeff(p1,x2),x1);
(%o11)                                 2
(%i12) p1: expand((x1 + x2)^2 +x2);

(%i22) p2: expand((x1 + x2)^3);
3          2       2        3
(%o22)                  x2  + 3 x1 x2  + 3 x1  x2 + x1
(%i23) makelist(coeff(p2, x1^i),i,1,3);
2
(%o23)                         [3 x2 , 3 x2, 1]

-sen

On Mon, 15 Jan 2007, Neilen Marais wrote:

> Hi,
>
> If I have multivariate polynomials, how can I get extract the
> coefficients of the homogeneous terms? E.g.
>
> (%i138) expand((x1+x2)^2 + x2);
> (%o138) x2^2+2*x1*x2+x2+x1^2
>
> Now I'm looking for the coeffs of x2^2, x1*x2, x^1, c, preferably as a
> list. So for this example I'd want [1, 2, 1, 0].
>
> What I actually want to do is get the weights needed to represent
> any polynomial of a given homogeneous degree i.t.o. another
> polynomial basis of the same function space. I'm representing a finite
> element approximation as a weighted sum of a set of basis functions, set
> A. Given a basis function set B that covers the same function space as set
> A I'd like to find the needed weights for set B given the weights for set
> A.
>
> My thinking went along the lines of representing the basis functions of
> each set i.t.o. their homogeneous coefficients thereby turning it into a
> matrix problem. Is there a better way to do this that I'm missing?
>
> Thanks
> Neilen
>
>
>
>
>
>

--
---------------------------------------------------------------------------
| Sheldon E. Newhouse            |    e-mail: sen1 at math.msu.edu           |
| Mathematics Department         |       				   |
| Michigan State University      | telephone: 517-355-9684                |
| E. Lansing, MI 48824-1027 USA  |       FAX: 517-432-1562                |
---------------------------------------------------------------------------
```