MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Is it possible to impose a condition on an iterator of

  • To: mathgroup at smc.vnet.net
  • Subject: [mg101606] Re: [mg101499] Is it possible to impose a condition on an iterator of
  • From: "Elton Kurt TeKolste" <tekolste at fastmail.us>
  • Date: Fri, 10 Jul 2009 23:24:22 -0400 (EDT)
  • References: <200907090552.BAA16854@smc.vnet.net>

Sum need not use an arithmetic progression of its indices -- any set
will do: 

In[60]:= Sum[f[i],{i,{1,5,7,3,30,whatever}}]
Out[60]= f[1]+f[3]+f[5]+f[7]+f[30]+f[whatever]

So the solution is to specify only the indices desired, in your case:

In[51]:= Sum[f[i], {i, Union[Range[5], Range[13, 20]]}]
Out[51]=
f[1]+f[2]+f[3]+f[4]+f[5]+f[12]+f[13]+f[14]+f[15]+f[16]+f[17]+f[18]+f[19]+f[20]

Or, for your function:

In[49]:= f[a_]:=a^2-3 a/(4 a^2);Sum[f[i], {i, Union[Range[5], Range[13,
20]]}]
Out[49]= 68197048951/28217280

There is a caveat, of course: if the range of indices is inherent to the
function and not incidental to the particular sum, then the restriction
should be built into the function:

In[62]:= f[a_/;6<a<13]:=0;f[a_]:=a^2-3 a/(4 a^2);
         Sum[f[i],{i,Range[20]}]
Out[62]= 65147819131/28217280

Kurt TeKolste

On Wed, 08 Jul 2009 21:52 -0400, "Mauro" <mauro at NONOyahoo.com> wrote:
> I would like to perform a summation of this type, 
> 
> Sum[a^2 - 3 a/(4 a^2), {a, 1, 20}]
> 
> excluding however some values of the iteratore, I would for instance
> like to exclude the values than to greater of 6 and inferior to 12. Is
> it possible?
> 
> Thanks
> 


  • Prev by Date: Re: Fast calculation of pair correlation function
  • Next by Date: Re: Help with FindRoot
  • Previous by thread: Re: Is it possible to impose a condition on an iterator
  • Next by thread: Re: Is it possible to impose a condition on an iterator of the summation ?