0
votes

I want to automatically calculate expansions of polynomials where there are variables (x1,x2,...) as well as coefficients (c1,c2, ...). My goal is to calculate p(1)*(c1*x1+c2*x2+...)^n+ ... + p(n)*(c1*x1+c2*x2+...)^n .

As you can notice the resulting expression can be written as F(x1,x2...)*g(c1,c2,...) [where F is a row matrix and g is column matrix], i.e. there is some multiplicative decoupling between the coefficients and the variables.

Right now I use the MATLAB symbolic toolbox and construct F and g by manually examining the resulting symbolic expansions. This is not very feasible as if n is big and c=(c1,c2,...) is too big there are too many terms and it is no longer possible manually. For instance for (c1*x1+c2*x2+c3) and n=2, what I want is following.

>> p=[2 5]

p =

     2     5

>> syms c1 c2 c3
>> syms x1 x2
>> expression= p(1)*(c1*x1+c2*x2+c3)^2 + p(2)*(c1*x1+c2*x2+c3);
>> expand(expression)

ans =

2*c1^2*x1^2 + 4*c1*c2*x1*x2 + 4*c1*c3*x1 + 5*c1*x1 + 2*c2^2*x2^2 + 4*c2*c3*x2 + 5*c2*x2 + 2*c3^2 + 5*c3

>> F=[5*x1 5*x2 5 4*x1*x2 4*x1 4*x2 2*x1^2 2*x2^2 2]

F =

[ 5*x1, 5*x2, 5, 4*x1*x2, 4*x1, 4*x2, 2*x1^2, 2*x2^2, 2]

>> g=[c1 c2 c3 c1*c2 c1*c3 c2*c3 c1^2 c2^2 c3^2].'

g =

    c1
    c2
    c3
 c1*c2
 c1*c3
 c2*c3
  c1^2
  c2^2
  c3^2

>> expand(F*g)

ans =

2*c1^2*x1^2 + 4*c1*c2*x1*x2 + 4*c1*c3*x1 + 5*c1*x1 + 2*c2^2*x2^2 + 4*c2*c3*x2 + 5*c2*x2 + 2*c3^2 + 5*c3

I have found the following question and it looks like there may be a way to do it automatically using conv etc. If one can come up with an automated solution (or at least some idea towards such automation) for the case where x=(x1,x2) and c=(c1,c2,c3) and n=2, the case depicted above; I guess I may be able to generalize it to higher dimensional cases.

Note: the ordering of terms in F or g does not matter, given that they are ordered in some structured way.

1

1 Answers

2
votes

The coefficients from different terms don't overlap. The first term, p(1)*(c'*x)^1, has only terms of degree 1 in xi and ci, and so on. So it becomes a matter of computing the coefficients of one term at a time.

That, too, has a "simple" expression:

p(k)*(c'*x)^k = sum(i1,..,im>=0 with sum(i_)=k) 
    M(k;i1,..,im)*x1^i1*...*xm^im * c1^i1*...*cm^im

where the summation is such that the sum of all i equals k, and M is the multinomial coefficient.

For m=3, n=2, the i's would be in the order of your example: 110,101,011,200,020,002. M(2;110)=2 so the first term is `p(2)*M(2;110)*x1*x2 = 4*x1*x2'.

Your F and g terms are:

F(...) = p(k)*M(k;i1,..,im)*x1^i1*...*xm^im
g(...) = c1^i1*...*cm^im