Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have a problem with Mathematica's symbolic manipulations. As an example, consider the following expression:

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

How do I get Mathematica to expand it 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$$

What I mean is: what functions do I apply to get the product to expand and the summation operator to distribute?

share|improve this question
1  
You are requesting two changes: first to Expand the products in the summation and second to Distribute the action of Sum over the addition. Consulting the help pages for Expand and Distribute will answer your question. –  whuber Dec 26 '12 at 18:15

1 Answer 1

up vote 13 down vote accepted
Distribute @ Sum[-2 Subscript[x, i] (-a Subscript[x, i] - b + Subscript[y, i]) // Expand,
                 {i, n}] == 0

enter image description here

share|improve this answer
    
thanks a lot :] –  Misery Dec 26 '12 at 18:38
    
How can one make the 2a and 2b factors come out in front of the sums? (and in general any variables that do not depend on the summation index)? –  Andrei May 9 '13 at 13:26
    
One can play with pattern matching, e.g. let the resulting expression be expr, then expr /. {Sum[Times[c_, d__], List[i_, n_]] :> c Sum[Times[d], List[i, n]]} does what you want. In more general cases one can work with ReplaceRepeated (//.) and (or) restrict pattern like e.g. c_?NumericQ. –  Artes May 9 '13 at 14:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.