# Summation limits [closed]

The Sum is a built-in function in Mathematica, so the summation limits must be assigned. What I need to know is how to use a value computed in a separate Module as a Sum upper limit.

-

## closed as unclear what you're asking by Mr.Wizard♦Sep 23 '13 at 11:46

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

Please add a concrete (small) example. –  b.gatessucks Sep 22 '13 at 8:56
You should be able to use it directly. For example upper = Prime[15]; and then Sum[3 x, {x, 1, upper}] -- if this is what you need the question will be closed as a basic syntax question; if it is not what you need we will require an example that demonstrates your problem. –  Mr.Wizard Sep 22 '13 at 9:11
indeed the Sum is to be used several times with varying upper limits. each time the upper limit is to be computed in a separate Module, e.g.: –  ibrahim sadiq Sep 22 '13 at 9:39

The upper limit does not need to be assigned. You can define a function as follows:

mySum[u_]:=Sum[yourCodeHereShouldDependOnN[n],{n,1,u}]


For example,

mySum[u_] := Sum[a[i], {i, 1, u}]
mySum[3]


yields

a[1] + a[2] + a[3]

-

If you are looking for, as you say in your last comment, the upper limit to be computed using a different Module each time, perhaps you want something like

m[1] := Module[{}, somecode];
m[2] := Module[{}, someothercode];
mySum[u_] := Sum[a[i], {i,1,m[u]}]


For example, with the above definition of mySum,

m[1] := Module[{}, 15];
mySum[1]


yields a[1]+a[2]+...+a[15].

-