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

MathGroup Archive 2013

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

Search the Archive

Re: Skipping Elements in Sum

  • To: mathgroup at smc.vnet.net
  • Subject: [mg131789] Re: Skipping Elements in Sum
  • From: scottcnoble at gmail.com
  • Date: Sun, 6 Oct 2013 03:46:34 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-outx@smc.vnet.net
  • Delivered-to: mathgroup-newsendx@smc.vnet.net
  • References: <diabl5$ihc$1@smc.vnet.net>

On Sunday, October 9, 2005 2:00:05 AM UTC-4, qcade... at gmail.com wrote:
> Does anyone know how to skip elements using the mathematica sum? e.g.
> take the sum of all i, where i not equal to j.

mySum[expr_,min_,max_,excl_] := Block[
				       {newlist,i,n},
				       newlist=Complement[Table[i,{i,min,max}],excl];
				       Sum[ expr[newlist[[i]]], {i,1,Length[newlist]}]
				     ]
where "expr" is a function representing the argument of the sum,  "min" is the minimum value of the index, "max" is the maximum value of the index, and "excl" is the list of indices to exclude from the sum. 

You can do this with Product[] as well...




  • Prev by Date: Dynamically setting {min, max} in Angular Gauge[] & speed it up.
  • Next by Date: Re: NonlinearModelFit properties are (suddenly) Missing[]
  • Previous by thread: Dynamically setting {min, max} in Angular Gauge[] & speed it up.
  • Next by thread: Re: Skipping Elements in Sum