# How do I expand a sum (again)? [duplicate]

Possible Duplicate:
How do I expand a sum?

How do I expand an equation in the given form:

$\sum _{i=1}^n -2 x_i \left(-a x_i-b+y_i\right)=0$

into this form:

$-\sum _{i=1}^n x_i y_i +a \sum _{i=1}^n x_i^2+b \sum _{i=1}^n x_i=0$

I know that I've asked this question, but this answer works only if the expression is being edited at the very moment. How to expand it and to distribute sum when I have such an expression saved into variable:

$Eq=\sum _{i=1}^n -2 x_i \left(-a x_i-b+y_i\right)=0$

Distribue[Eq] and Expand[Eq] return just unchanged Eq.

Regards

-

## marked as duplicate by whuber, Artes, R. M.♦Jan 7 '13 at 15:53

f[n_] := Sum[-2 x[i] ( - a x[i] - b + y[i]), {i, n}]
eq = f[n] == 0;
eq /. Sum[x__, y_] :> Distribute@Sum[Expand@x, y]
(*
-> Sum[2*b*x[i], {i, n}] + Sum[2*a*x[i]^2, {i, n}] + Sum[-2*x[i]*y[i], {i, n}] == 0
*)

-
That is just something I wanted to avoid. In my calculations Eq is a result of previous derivations, and to make my code flexible I cannot define it that way f[n_]:=... I need to work with my eq expression – Misery Jan 7 '13 at 12:59
@Misery Use the last statement only – Dr. belisarius Jan 7 '13 at 13:07
Thanks, now it works as expected :] I am quite a noob in Mathematica, therefore I find some answers hard to use. – Misery Jan 7 '13 at 14:06
@Misery I found your comment "That is just something I wanted to avoid" somewhat stubborn for a "noob" – Dr. belisarius Jan 7 '13 at 14:16
Well... I am quite experienced programmer in SCILAB and C++ and I must admit, that sometimes I get really irritated if I cannot even understand a code snippet :p Sorry! Didn't mean to "sound" that way. – Misery Jan 7 '13 at 14:19