Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question

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.

2  
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

2 Answers 2

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]

share|improve this answer

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].

share|improve this answer

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