Re: Re: Skipping Elements in Sum
- To: mathgroup at smc.vnet.net
- Subject: [mg61204] Re: [mg61160] Re: Skipping Elements in Sum
- From: Andrzej Kozlowski <andrzej at yhc.att.ne.jp>
- Date: Wed, 12 Oct 2005 01:43:27 -0400 (EDT)
- References: <did35k$qh9$1@smc.vnet.net> <difr6v$fe8$1@smc.vnet.net> <200510110849.EAA17372@smc.vnet.net>
- Reply-to: Andrzej Kozlowski <andrzej at akikoz.net>
- Sender: owner-wri-mathgroup at wolfram.com
It seems to me that the main point is a bit different. Actually there are two quite different reasons to use Sum. The first is when you want to compute the sum of a finite number or numbers. In this case one does not really need Sum: using Table and Plus (or Total or Trace) will often be more convenient and make "skipping" even easier and safer than with Sum and KroneckerDelta. But there is a completely different situation when you actually do need to use Sum and that is when you want to use Mathematica's ability to compute symbolic sums of expressions with variable (or infinite) number of terms. Using KroneckerDelta in such cases usually simply does not work and the best approach is to try to "re-index" the sum. here is a trivial example. Consider the sum of n terms: Sum[1/2^i, {i, 1, n}] (-1 + 2^n)/2^n Now suppose we only want to compute the sum over the even numbers n. We could try: Sum[KroneckerDelta[0, Mod[i, 2]]*(1/2^i), {i, 1, n}] This will work fine when n is a number: Sum[KroneckerDelta[0, Mod[i, 2]]*(1/2^i), {i, 1, 51}] 375299968947541/1125899906842624 but not when n is a symbol: Sum[KroneckerDelta[0, Mod[i, 2]]*(1/2^i), {i, 1, n}] Sum[KroneckerDelta[0, Mod[i, 2]]/2^i, {i, 1, n}] For loops will be of no help here; in such cases the only thing to do is to re-index and hope that Mathematica knows the answer (which it often does): Sum[1/2^(2*i), {i, 1, Floor[n/2]}] ((1/3)*(-1 + 2^Floor[n/2])*(1 + 2^Floor[n/2]))/ 2^(2*Floor[n/2]) Andrzej Kozlowski Tokyo, Japan On 11 Oct 2005, at 17:49, Jens-Peer Kuska wrote: > Hi, > > the main problem with > > Sum[(1-KroneckerDelta[i,j])*a[i,j],{i,1,10},{j,1,10}] > > ist that a[i,j] in many physical applications > contain > a singularity and Mathematica try to evaluate > a[i,i] > before it find out that the term > (1-KroneckerDelta[i,j]). > In the worst case it get 0*Infinity and don't know > what > to do with it. > > Regards > Jens > > "Richard J. Fateman" <fateman at eecs.berkeley.edu> > schrieb im Newsbeitrag > news:difr6v$fe8$1 at smc.vnet.net... > | Sum[a[i],{i,low,j-1}]+Sum[a[i],{i,j+1,high}] may > be far more > | useful in many ways, since you can tell how many > elements there > | are: if low<j<high then high-low else > high-low+1 and > | other useful symbolic info. > | > | Symbolically manipulating objects with holes > shot in them with > | Delta functions is not so easy or reliable. > | > | If all you want to do is add them, you can use a > For loop and > | subtract the excluded elements, but that's not > what you asked. > | > | You could try asking a more specific question > about what you > | really want to do with Sum. > | RJF > | > | > | > | Bill Rowe wrote: > | > | > On 10/9/05 at 1:36 AM, qcadesigner 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. > | > > | > > | > Yes. > | > > | > One way to do this with the Sum function would > be to use the KroneckerDelta function as follows: > | > > | > Sum[Subscript[a, n](1 - KroneckerDelta[n, 3]), > {n, 5}] > | > > | > Another way to create the same sum would be > | > > | > Total[Table[Subscript[a, n], {n, > 5}][[Complement[ > | > Range[5], {3}]]]] > | > > | > and there are many other ways to achieve the > same result. Which is best depends on exactly what > you are trying to accomplish. > | > -- > | > To reply via email subtract one hundred and > four > | > > | > > >
- References:
- Re: Skipping Elements in Sum
- From: "Jens-Peer Kuska" <kuska@informatik.uni-leipzig.de>
- Re: Skipping Elements in Sum