Tell me more ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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:

enter image description here

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?

share|improve this 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
1  
I have updated the answer, please look at the EDIT1 and EDIT2. – maximus Jan 12 '12 at 9:18
2  
You should do the distribution yourself. Mathematica won't split sums like $\sum(p+q)$ into $\sum p+\sum q$ for you. – J. M. Jan 12 '12 at 9:32
2  
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
show 9 more comments

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.