MathGroup Archive 2006

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

Search the Archive

Re: List Operations

  • To: mathgroup at smc.vnet.net
  • Subject: [mg65713] Re: List Operations
  • From: "Scout" <Scout at nodomain.com>
  • Date: Sun, 16 Apr 2006 01:45:19 -0400 (EDT)
  • References: <e1nn6s$lmm$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

"LectorZ" <lectorz at mail.ru>
 news:e1nn6s$lmm$1 at smc.vnet.net...
> Hi guys,
>
> My question:
>
> mylist={{1,a, b},{1,a, b},{1,a,
> b},{2,b,z},{2,b,z},{2,b,z},{2,b,z},....,{n,x,y},{n,x,y},{n,x,y},...{n,x,y}}
>
> The sublists are of different length.
>
> I need to calculate the product between the 2nd and 3rd element of
> every sublist (e.g. a*b) and then add them up according to the 1st
> element: sum of all products where the 1st element is 1, 2, ...n.
>
> The result should be a list like that:
> {{1,a*b+a*b+a*b},{2,b*z+b*z+b*z+b*z}, ...,{n, x*y+x*y+x*y+...+x*y}}
>
> Thank you for your help.
>
> LZ
>

This might help you:

In[1]:= Plus@@ # /. {n_, x_}->{n / Length[#], x} & /@ Split[mylist /. {n_, 
a_, b_}->{n, a*b}, First[#1]==First[#2]&]


Cheers,
    ~Scout~


  • Prev by Date: Re: List Operations
  • Next by Date: Re: NDSolve
  • Previous by thread: Re: List Operations
  • Next by thread: Re: List Operations