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?