MathGroup Archive 2005

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

Search the Archive

Re: how to make conditional summation

  • To: mathgroup at smc.vnet.net
  • Subject: [mg55580] Re: how to make conditional summation
  • From: "Dan" <dantopa at gmail.com>
  • Date: Wed, 30 Mar 2005 03:21:17 -0500 (EST)
  • References: <d2b4ki$76i$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Xiao Jun Jun wrote:
> Hi, All,
>
> Say, Sum[f[m],{m,-N,N}] with N != 0
> Any suggestions?
>
> Regards.
> Xun

Hi Xun:

I have a couple of ideas. First, I hope you have noticed by now that
capital N (the numeric operator) is a reserved symbol.

1. If you can compute f[0] (no error messages, no time penalty), the
simplest way is to Map the function across the list and subtract the
zero case.

m = Table[i, {-n,n}]
f/@m - f[0]

2. Create a list of m values without the zero.
There are a few ways to do this. Pick the one you are most comfortable
with.
a. m1 = Table[i,{i,_n,N}]; m = Select[m1,#!=0&];
b. m = Join[Table[i, {i,-n,-1}],Table[i, {i,n}]]

Map the function over the list: f/@m

3. If you had a list and more than one selection criteria then I would
use this.

(* exclude 0, exclude odd numbers *)
fcn=(#!=0 && EvenQ[#])&
m = Range[-3,3];

sm = 0;  (* clear summation variable *)
Do[      (* loop through list m *)
  If[fcn[m[[1]]],sm+=f[m[[i]];    (* apply criterion *)
  ,{i, Length[m]}]
sm

output = f[-2] + f[2]

Notice that for integer values you can build the list using Range:
m = Range[-n,n]

Hope this helps.
Dan


  • Prev by Date: Re : intersection point from listplots
  • Next by Date: Re: front end complaint (ui design flaw?)
  • Previous by thread: Re: how to make conditional summation
  • Next by thread: Position function