Message Boards Message Boards

0
|
3125 Views
|
3 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Collect coefficients in a polynomial defined by symbolic summation?

Posted 6 years ago

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?

POSTED BY: Aurelien Bibaut
3 Replies

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]
POSTED BY: Gianluca Gorni

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 BY: Gianluca Gorni

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

POSTED BY: Aurelien Bibaut
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