# Mathematica: Solve function problem [closed]

I have entered the following commands in Mathematica:

S = Sum[

(y[i] - a *x[i] - b)^2,

{i, 1, n}

]

Equation1 = D[S, a] == 0;

Equation2 = D[S, b] == 0;

Solve[Equation1 && Equation2, {a, b}]

The result of the last operation, the Solve, was nothing: {}

However all the steps before Solve operation were correctly calculated. If I put a certain value in the $n$ variable, so that the sum becomes with defined limit (for example $i=1..n, n = 10$) then everything is solved correctly.

What is the problem here and how to resolve it?

The program I made was simple Least Squares method. I just wanted to see the result in case when the variable $n$ is not fixed to some value.

EDIT1: The result of the Solve function if I set the $n = 2$ will be:

$\left\{\left\{a\to -\frac{-y[1]+y[2]}{x[1]-x[2]},b\to -\frac{x[2] y[1]-x[1] y[2]}{x[1]-x[2]}\right\}\right\}$

EDIT2: In case of not fixed $n$ value the result would be:

But I get empty list instead.

Here is what Equation1 and Equation2 contains if the $n$ value is not fixed:

$\sum _{i=1}^n -2 x[i] (-b-a x[i]+y[i])==0$

$\sum _{i=1}^n -2 (-b-a x[i]+y[i])==0$

So the Mathematica must handle this, but why it can't?

-

## closed as off topic by Lord_Farin, Serkan, Amzoti, Henry T. Horton, rschwiebMay 22 '13 at 16:25

Questions on Mathematics Stack Exchange are expected to relate to math within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

How have you defined x and y? If they are lists and not functions you should say x[[i]] rather than x[i]. –  Dan Brumleve Jan 12 '12 at 8:57
I didn't define them as something. They are also not fixed values. I just entered them as you see above, in the form x[i], y[i]. As indexed variables –  maximus Jan 12 '12 at 9:04
I have updated the answer, please look at the EDIT1 and EDIT2. –  maximus Jan 12 '12 at 9:18
You should do the distribution yourself. Mathematica won't split sums like $\sum(p+q)$ into $\sum p+\sum q$ for you. –  Ｊ. Ｍ. Jan 12 '12 at 9:32
Actually, the Symbolic Computing Package presented at the recent Tech Conference can split sums and integrals (along with lots of other functionality). It's worth having a look at. –  Simon Jan 12 '12 at 12:34