4

I want to solve an equation with sum in Mathematica, e.g.,

$$\sum _i \frac{a_i}{x}=1$$

But when I input this:

Solve[Sum[Subscript[a, i]/x, i] == 1, x]

Mathematica will tell me:

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

If I remove the $x$ from the equation like this:

$$\frac{\sum _i a_i}{x}=1$$

And:

Solve[Sum[Subscript[a, i], i]/x == 1, x]

Then Mathematica can actually solve it. But this seems a bit troublesome and strange to me. So am I using it incorrectly? What should I input in this case, thanks!

Ivan Xiao
  • 141
  • This question is off-topic here. Please see FAQ. – Sasha Nov 17 '11 at 20:41
  • 1
    I think this question is on-topic. Please consider this my vote against closure. – Srivatsan Nov 17 '11 at 21:01
  • @OP: What is your desired output? – Listing Nov 17 '11 at 21:54
  • @Sasha I checked the tag and find similar questions, so I thought it is on topic. – Ivan Xiao Nov 17 '11 at 22:16
  • @Listing I just want to solve this equation. The first one is more natural to me but it does not work. Another reason is, I may obtain this equation from the previous output in the first form. – Ivan Xiao Nov 17 '11 at 22:17
  • Your equation is ambiguous even for normal persons... You don't even specify which values $i$ is looping over in your sum. If it is some series I doubt mathematica can do this as they only handle finite solutions according to my knowledge. – Listing Nov 17 '11 at 22:21
  • @IvanZ.Siu This is off-topic for this site. You have found a satisfactory work-around already. If you wish Mathematica could do it automatically, you should consider contacting Wolfram Research directly and filing a suggestion. – Sasha Nov 17 '11 at 22:24
  • 3
    @IvanZ.Siu It is not surprising that mathematica cannot handle this, since it is not clear at all what mathematica should do to a sum with unspecified summation range in general. Please consider supporting the proposals for a mathematica stackexchange site: http://area51.stackexchange.com/proposals/15787/mathematica – Phira Nov 17 '11 at 23:19
  • @Listing I just want to do thing symbolically. Indeed I can specify range for i as 1..n, it doesn't matter. – Ivan Xiao Nov 18 '11 at 04:55
  • 1
    @Phira Thanks. Sure I will. – Ivan Xiao Nov 18 '11 at 04:56

1 Answers1

6

Mathematica does not have the (user facing) ability to do manipulations of unevaluated sums or integrals. However, simple cases are easily programmed by hand.

I assume that the indefinite sum that you're really interested in is more complicated than the example you provided. Here's some quick code for taking common factors out of sums and expanding sums. You can write similar code to reverse these operations.

factorSum[expr_] := expr /. Sum[x_, i_] :> Module[
    {factx = Factor[x], common, 
     ii = If[Head[i] === List, First[i], i]},
    common = If[Head[factx] === Times, Select[factx, FreeQ[#, ii]&], 1];
    common Sum[factx/common, i]]
expandSum[expr_] := expr /. Sum[x_, i_] :> Module[
    {expandx = Expand[x], ii = If[Head[i] === List, First[i], i]},
    If[Head[expandx] === Plus, 
     Total@Table[Sum[term, i], {term, List @@ expandx}], Sum[x, i]]]

And here it is in action (you can replace the indefinite i with a more definite {i, n1, n2} and it still works):

In[3]:= factorSum[Sum[a[i]*x*y*b^i + y*c[i], i]]
        expandSum[%]
        factorSum[%]

Out[3]= y*Sum[b^i*x*a[i] + c[i], i]

Out[4]= y*(Sum[b^i*x*a[i], i] + Sum[c[i], i])

Out[5]= y*(x*Sum[b^i*a[i], i] + Sum[c[i], i])

Note that it is a little slow, because every time a new Sum is produced, Mathematica tries to see if it can evaluate it. If you were serious about implementing formal manipulations of sums and integrals, you'd have to define new symbolicSum-type objects or turn off the built in behaviour while your code is running.


Anyway, here's your original problem:

In[6]:= Solve[factorSum[Sum[Subscript[a, i]/x, i]] == 1, x]
Out[6]= {{x -> Sum[Subscript[a, i], i]}}
Simon
  • 1,136
  • Yes I do have a much more complicated problem to solve. I am just trying to show a minimal example. So basically Mathematica cannot handle unevaluated sums. I do wish I can achieve things in a symbolic way. Thanks a lot. – Ivan Xiao Nov 18 '11 at 04:58