Message Boards Message Boards

GROUPS:

Collect coefficients in a polynomial defined by symbolic summation?

Posted 4 months ago
477 Views
|
3 Replies
|
1 Total Likes
|

Hi all, I'd like to distribute the squared sum and collect the coefficients in front of n and n^2 in the following expression:

Sum[a[i] (n (n - 1) + 2 n), {i, 1, K}] - Sum[a[i] n, {i, 1, K}]^2,

Would anyone know how to do this?

3 Replies

Maybe something like this

Collect[(n (n - 1) + 2 n) Sum[a[i] , {i, 1, K}] -
  n^2 Sum[a[i]
     Sum[a[j], {j, 1, K}], {i, 1, K}],
 n]

Or did you want to do it programmatically?

Posted 4 months ago

Thank your for your reply Gianluca! However, I was looking for a way to do it programmatically. Would you know if this is possible?

You can do it with replacement patterns:

extractCommonFactor = 
  Sum[r_*s_, {sumIndex_, lmts__}] /; FreeQ[s, sumIndex] :>
   s*Sum[r, {sumIndex, lmts}];
expandSquare = Sum[r_, {sumIndex_, lmts__}]^2 :>
   Sum[r*(Sum[r, {sumIndex, lmts}] /. sumIndex -> sumIndex2),
    {sumIndex, lmts}];
Sum[a[i] (n (n - 1) + 2 n), {i, 1, K}] - Sum[a[i] n, {i, 1, K}]^2 /.

   extractCommonFactor /. expandSquare
Collect[%, n]
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract