4
$\begingroup$

I'm trying to check some equations I did on paper, but I have troubles getting Mathematica to solve them.

The equation (with Latex):

equation

My input: Sum[2 Subscript[x, i] (b Subscript[x, i] - Subscript[y, i]), {i, 1, n}] == 0

If I want to solve for b with Solve[%, b] it says:

Solve::nsmet: This system cannot be solved with the methods available to Solve.

Are the indices the problem? I tried it with x[i] and y[i], but that didn't work either.

What am I missing?

$\endgroup$
  • $\begingroup$ It's the n that's the problem. Mathematica doesn't do sums with variable upper limits very well. You have to put in values for n in order for Solve to find a solution (which it does, of course, easily). $\endgroup$ – march Oct 24 '16 at 20:07
  • $\begingroup$ How about Function[{n}, Reduce[\!( *UnderoverscriptBox[([Sum]), (i = 1), (n)](2\ x[ i]\ ((b\ x[i] - y[i])))) == 0, b, Reals]]? $\endgroup$ – user64494 Oct 24 '16 at 20:12
  • $\begingroup$ @user64494 I copy and pasted that into Mathematica and it says "Syntax::sntxb: Expression cannot begin with "\!(*UnderoverscriptBox[([Sum]),(i=1),(n)](2\x[i]\((b\x[i]-y[i]))))==0." I'm not familar with that notation. What are the `\` for? $\endgroup$ – MWin123 Oct 24 '16 at 20:25
  • $\begingroup$ @march It works with a value for n, but I need the general solution. $\endgroup$ – MWin123 Oct 24 '16 at 20:26
  • 1
    $\begingroup$ Right, that's that the point. Mathematica doesn't do well with symbolic sums. If you try a couple of different n's, you can verify that your general solution matches each specific case as evidence that your general solution is correct, but Mathematica doesn't know how to solve that equation, because it's hard to write down a general expression for the sum, and even if we could, it's likely to be of a nature that's hard to solve algebraically anyway. $\endgroup$ – march Oct 24 '16 at 20:32
5
$\begingroup$

maybe useful, if your expression is a polynomial in b you can factor it out of the sum and then get a symbolic result:

sum = Sum[2 Subscript[x, i] (b Subscript[x, i] -
     Subscript[y, i]), {i, 1, n}]
b /. First@Solve[
   sum == 0 /. 
    Sum[exp_, i_] :> Total@MapIndexed[b^(First@#2 - 1) Sum[#, i] &, 
       CoefficientList[exp, b] ], b]

enter image description here

| improve this answer | |
$\endgroup$
1
$\begingroup$

I think you are underestimating what some people hinted at of playing spot the pattern. You are allowed to help Mma out when he needs it.

Solve[Sum[2 Subscript[x, i] (b Subscript[x, i] - Subscript[y, i]), {i, 1, 1}] == 0, b]

$$ b=\frac{y_1}{x_1}$$

Solve[Sum[2 Subscript[x, i] (b Subscript[x, i] - Subscript[y, i]), {i, 1, 2}] == 0, b]

$$ b= \frac{x_1 y_1+x_2 y_2}{x_1^2+x_2^2}$$

Solve[Sum[2 Subscript[x, i] (b Subscript[x, i] - Subscript[y, i]), {i, 1, 3}] == 0, b]

$$ b= \frac{x_1 y_1+x_2 y_2+x_3y_3}{x_1^2+x_2^2+x_3^2}$$

We have a pattern which may or may not hold up but it is worth trying:

$$b=\frac{\sum _{k=1}^n x_k y_k}{\sum _{k=1}^n x_k^2}$$

This may not be what you were hoping for but it might be close to all that is possible. A general form in terms of elementary functions may not be possible.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Ok that is a good way to come around but still it means Mathematica can't solve this kind of question/equation (if upper bound of n is not defined). And Mathematica is considered in solving symbolic expressions, does this mean there is no software which can solve this kind of expression? By the way pattern recognition is a good idea. I am not working in the area of OP otherwise I could have tested if equation holds for all k. @bobbym $\endgroup$ – Jawad_Mansoor Mar 2 '17 at 14:59
  • 1
    $\begingroup$ @Jawad_Mansoor there has yet to be any piece of software except in the movies that can do it all for you. I doubt there ever will be. Hamming once said, "the purpose of computing is insight, not numbers." It is still true today. If Mma spits out the answer, then great, if not, then we can use it to play. Experimenting is a powerful new/old technique that Mma makes easier. $\endgroup$ – bobbym Mar 2 '17 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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