Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: Summation question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg85709] Re: Summation question
  • From: Albert Retey <awnl at arcor.net>
  • Date: Tue, 19 Feb 2008 07:08:54 -0500 (EST)
  • References: <fpdu7v$qlq$1@smc.vnet.net>

Hi,

> I want to make a summation like this:  Sum[f[i],{i, start,
> finish}]. What I want is that the sum be over a specific set like
> {1,3,5,7,11,13}. So the sum would be : f[1]+f[3]+f[5]+f[7]+f[11]+f[13]. The
> set I want to use is the primes. So, how do I use, if possible, Sum over a
> specific set ?
> 

In version 6 you can use a list of values as iterator in many functions, 
among them Table and Sum:

In[23]:= Sum[i,{i,{a,b,c}}]
Out[23]= a+b+c

So what remains is to construct a list of the values for which you want 
to sum, the following is a very simple way to extract the primes from 20 
to 30. If you will work with very large ranges, you might need something 
  smarter here:

In[28]:= Select[Range[20,30],PrimeQ]
Out[28]= {23,29}

In combination this will do what you need:

In[27]:= Sum[f[i],{i,Select[Range[5,20],PrimeQ]}]
Out[27]= f[5]+f[7]+f[11]+f[13]+f[17]+f[19]

hth,

albert


  • Prev by Date: Re: Making a lists with conditions
  • Next by Date: convex FindMinimum for a large vector
  • Previous by thread: Re: Summation question
  • Next by thread: Re: Summation question