How can I fix the warning for solving summation in Mathematica?

In summary: You're welcome! We're always happy to help and share our knowledge. Good luck with your studies and feel free to ask any further questions you may have.
  • #1
kaizen.moto
98
0
Hi everyone,

I have these warning solving summation:
*************************************************
In[1]: f[m_, n_] := 2 n + 3 m;

In[2]: g[m_, n_] := Sum[f[m, n], {m, 1, m, 2}, {n, n, 1}];

In[3]: g[1, 1]

During evaluation of In[3]:= Sum::itraw: Raw object 1 cannot be used as an iterator. >>

During evaluation of In[3]:= Sum::itraw: Raw object 1 cannot be used as an iterator. >>

Out[3]= Sum[f[1, 1], {1, 1, 1, 2}, {1, 1, 1}]
*************************************************

The idea is that I wanted to make summation of g[m,n] with variable m, from m=1 until m = m with step 2 and keeping variable n at all cycles. For instance:

g[5,3]= f[1,3]+f[3,3]+f[5,3]

or

g[19,5]=f[1,5]+f[3,5]+f[5,5]+...+f[19,5]

Please help me to solve this problem.

Thank you.
 
Physics news on Phys.org
  • #2
kaizen.moto said:
Hi everyone,

In[2]: g[m_, n_] := Sum[f[m, n], {m, 1, m, 2}, {n, n, 1}];

Sum::itraw: Raw object 1 cannot be used as an iterator. >>

The idea is that I wanted to make summation of g[m,n] with variable m, from m=1 until m = m

You want m to vary between 1 and m itself?
Is that possible?

How about changing the summation indexes names, like this

Code:
f[j_,k_]:=2 j+3k;
g[m_,n_]:=Sum[f[j,k],{j,1,m,2},{k,n,1}];

g[1,1]
   5
 
  • #3
To be honest, I have already changed the indexes and I got that output already. The thing is that it did not apply the same idea when it comes to Module command. This is because I put all my codes using Module.

So I am looking for another ways to represent the summation that would work with Module command.
 
  • #4
Can you perhaps show what the sums should be for m and n = 1,2,3...6?
Maybe people can just reverse engineer from what you want the sum to be to figure out what your code should look like.
That might be easier than trying to understand your code.
 
  • #5
Module won't prevent you from using an indexing variable.
 
  • #6
The code iam working with and given by Mathematica is as follow:
**************************************************************************
In[1]: qSolve[m_, n_]:=Module[{ggg, hhh, s, t}, ggg = 2 m + 3 n; hhh = Sum[ggg, {m, 1, s, 2}, {n, t}]];
In[2]: qSolve[5,3]

Sum::itraw: Raw object 1 cannot be used as an iterator. >>
Sum::itraw: Raw object 1 cannot be used as an iterator. >>

Out[2]: Sum[ggg$708, {1, 1, s$708, 2}, {1, t$708}]**************************************************************************


As an example, Iam expecting the output should read:
In[3]: qSolve[5,3] (meaning hhh = Sum[ggg,{m,1,5,2},{n,3}])
Out[3a]: ggg[1,3] + ggg[3,3] + ggg[5,3]
Out[3b]: 11 + 15 + 19
Out[3c]: 45

Please let me know how to solve the matter.
 
Last edited:
  • #7
Perhaps something like this?

In[1]:= ggg[m_,n_]:=2*m+3*n
In[2]:= qSolve[m_,n_]:=Sum[ggg[i,n],{i,1,m,2}]
In[3]:= Trace[qSolve[5,3],Plus|ggg]
Out[23]= {{ggg[1,3],2 1+3 3,2+9,11},{ggg[3,3],2 3+3 3,6+9,15},{ggg[5,3],2 5+3 3,10+9,19},11+15+19,45}

or

In[4]:= qqSolve[m_,n_]:=Module[{},Sum[ggg[i,n],{i,1,m,2}]]
In[5]:= Trace[qqSolve[5,3],Plus|ggg]
Out[5]= {{{ggg[1,3],2 1+3 3,2+9,11},{ggg[3,3],2 3+3 3,6+9,15},{ggg[5,3],2 5+3 3,10+9,19},11+15+19,45}}

By making this MUCH more complicated and including more things that you will not understand it would be possible to provide output much closer to the step by step display that you showed. But perhaps the output of Trace[] when limited to the patterns that I included as the last argument, or not even using Trace[] and just using qSolve[5,3] alone may be sufficient for what you actually need.

Your example of the output you needed was very helpful. Thank you. It would have required dozens of incomprehensible posts trying to figure out broken code before we might have guessed what you actually wanted.

I would strongly urge you to purchase a good book teaching how to use Mathematica if that is possible for you. "Applied Mathematica: Getting Started, Getting It Done" by Shaw and Tigg is very old and can be purchased used very cheaply. If you study every sentence in that book until you understand them you can learn much of what you need for the simplest use of Mathematica. "Mathematica Navigator" is an excellent book with many simple practical examples. You need the edition of the book that matches the version of Mathematica you have, the 2nd edition is for MMA5.x, the 3rd edition is for MMA 6 and perhaps a bit of 7, no edition covers the new material in version 8. "Mathematica Cookbook" is also good. Spending 100-200 intense hours learning the basics of Mathematica programming will make you far more productive and it will be much less frustrating for you and you will need to ask far fewer questions. Mathematica is VERY different from other programming languages. After perhaps 1000 hours of intense study when you think you are beginning to really understand how Mathematica works you may then be ready to understand that it is not actually working at all like you think it is and you start working on the next deeper level of understanding.
 
  • #8
The code and error message
Code:
qSolve[m_, n_]:=Module[
 {ggg, hhh, s, t},
 ggg = 2 m + 3 n; 
 hhh = Sum[ggg, {m, 1, s, 2}, {n, t}]];

[I]Sum::itraw: Raw object 1 cannot be used as an iterator. >>[/I]
[I]Sum::itraw: Raw object 1 cannot be used as an iterator. >>[/I]

Tell you that you are trying to use a number (m is a number, when you call qSolve[1,1] passing numbers to it ) as an iterator.

Basically you are trying to compute this

Sum[ 2*1+3*1,{1, 1, s, 2},{1,t}]

i.e. the sum of 5 when 1 changes from 1 to an unknown local s, step 2, and 1 going from 1 to an unknown local t, step 1.
No wonder Mathematica is complaining.
This is no module limitation.
You should get your indexes right, methinks.
 
  • #9
SredniVashtar said:
You should get your indexes right, methinks.
I agree. He is trying to use a constant as an iterator, so of course it fails.
 
  • #10
Just wanted to say thank you for all the comments. I really appreciate for the type of books recommended as so far I have only managed to refer to these books, Mathematica by Example 4 by Martha Abell & James Braselton and A Beginners Guide to Mathematica by David Mc Mahon. You guys are really helpful and very expert on this program. Thanks alot.
 

Related to How can I fix the warning for solving summation in Mathematica?

1. What is summation in Mathematica?

Summation in Mathematica is the process of finding the sum of a series or sequence of numbers. It is a built-in function that allows you to easily perform mathematical operations on a set of data.

2. How do I use the Summation function in Mathematica?

To use the Summation function, you can simply type "Sum" followed by the expression or series you want to sum, enclosed in curly braces. For example, Sum[{x, y, z}] will find the sum of x, y, and z. You can also specify the limits of the sum using the syntax "Sum[expression, {i, i_min, i_max}]."

3. Can I use variables in the Summation function?

Yes, you can use variables in the Summation function. Variables can be defined using the "Set" or "SetDelayed" functions in Mathematica. For example, you can define x as x = 2 and then use it in the Summation function as Sum[x, {i, 1, 10}].

4. How do I evaluate infinite sums in Mathematica?

To evaluate infinite sums, you can use the "Limit" function in Mathematica. For example, if you want to evaluate the infinite sum of 1/n, you can use the syntax Limit[Sum[1/n, {n, 1, m}], m -> Infinity]. This will give you the value of the infinite sum as a limit.

5. Are there any special functions for summation in Mathematica?

Yes, there are several special functions for summation in Mathematica, such as "SumConvergence" and "SummationLimit." These functions can be used to test the convergence of a series and find the limit of a sum, respectively. You can also use the "SummandSequence" function to find the general term of a series.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
942
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
4K
  • General Math
Replies
9
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
3K
Replies
2
Views
1K
Back
Top