Re: sum with lists
- To: mathgroup at smc.vnet.net
- Subject: [mg40565] Re: sum with lists
- From: atelesforos at hotmail.com (Orestis Vantzos)
- Date: Thu, 10 Apr 2003 03:39:19 -0400 (EDT)
- References: <b70npo$9gd$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Begin with d1=Take[d,(n/2)+1] to cut the list down to the triplets you want to use in the sum. Then d2=Transpose[d1] will return a list of the form {{x0,x1,...},{y0,...},{z0,...}} The sum you want is the inner product d2[[1]].d2[[3]] Oneliner: mySum[d_]:=With[{d2=Transpose[Take[d,(n/2)+1]]},d2[[1]].d2[[3]]] Orestis "Nathan Moore" <nmoore at physics.umn.edu> wrote in message news:<b70npo$9gd$1 at smc.vnet.net>... > Another list question. Suppose that I have the list > d={ > {x0,y0,z0}, > {x1,y1,z1}, > {x2,y2,z1}, > ... > {xn,yn,zn}} > > and now I'd like to calculate the sum, > Sum[x[i]*z[i],{i,0,n/2}] > > I tried > Sum[d[[i, 1]]*d[[i, 3]], {i, 0, 10}] > with little success > > thanks, > > Nathan Moore, > University of Minnesota Physics