Re: summations!
- To: mathgroup@smc.vnet.net
- Subject: [mg10973] Re: summations!
- From: Allan Hayes <hay@haystack.demon.co.uk>
- Date: Sun, 15 Feb 1998 02:10:38 -0500
- References: <6c3dq1$1ct@smc.vnet.net>
Rahul Swaminathan wrote:
>
> guys i am new to mathematica ... and want to do summations... if i have
> 2 nested summations one ranging from say i = 0 to i = N and the inner
> one from j = 0 to j = M , how do i represent it in mathematica for the
> under.
>
> \sigma{_i = 0}{N} \sigma{_j = 0}{M} [Sin ( \theta{_i,_j} ) * Cos (
> \phi{_i} ) ]
>
> an early responce would be great:)
>
> regards,
> -sr
Copy the notation that you have given In[1]:=
Sum[Sum[a[i,j],{j,0,M}],{i,0,N}]
Out[1]=
Sum[Sum[a[i, j], {j, 0, M}], {i, 0, N}]
or sum over two indices (notice that the index for the outer summation
in the previous form comes first)
In[2]:=
Sum[a[i,j],{i,0,N},{j,0,M}]
Out[2]=
Sum[a[i, j], {i, 0, N}, {j, 0, M}]
Numerical version of this:
In[3]:=
Sum[a[i,j],{i,0,2},{j,0,3}]
Out[3]=
a[0, 0] + a[0, 1] + a[0, 2] + a[0, 3] + a[1, 0] + a[1, 1] +
a[1, 2] + a[1, 3] + a[2, 0] + a[2, 1] + a[2, 2] + a[2, 3]
Limits for inner indices can be functions of outer indices In[4]:=
Sum[Sum[a[i,j],{j,0,i+1}],{i,0,2}]
Out[4]=
a[0, 0] + a[0, 1] + a[1, 0] + a[1, 1] + a[1, 2] + a[2, 0] +
a[2, 1] + a[2, 2] + a[2, 3]
In the summation over multiple indices version this become: Limits for
later indices can be functions of earlier indices.
In[5]:=
Sum[a[i,j],{i,0,2},{j,0,i+1}]
Out[5]=
a[0, 0] + a[0, 1] + a[1, 0] + a[1, 1] + a[1, 2] + a[2, 0] +
a[2, 1] + a[2, 2] + a[2, 3]
--
Allan Hayes
Training and Consulting
Leicester, UK
hay@haystack.demon.co.uk
http://www.haystack.demon.co.uk
voice: +44 (0)116 271 4198
fax: +44 (0)116 271 8642