Re: Programing operations with lists

• To: mathgroup at smc.vnet.net
• Subject: [mg50865] Re: Programing operations with lists
• From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
• Date: Sat, 25 Sep 2004 01:55:03 -0400 (EDT)
• Organization: Universitaet Leipzig
• References: <cj0n6t\$ld2\$1@smc.vnet.net>
• Reply-to: kuska at informatik.uni-leipzig.de
• Sender: owner-wri-mathgroup at wolfram.com

```Hi,

list1 = {{0.71, 7378}, {1.6, 768}, {2, 2269}, {2.05, 0}, {2.35, 0},
{2.4,
2608}, {2.6, 193}, {2.8, 4187}, {2.85, 204}, {2.95, 134}, {3.2,
776}, {3.25, 24}, {3.6, 6209}, {3.65, 0}, {3.7, 2809}, {3.95,
1923}, {4, 2627}, {4.1, 25}, {4.15, 1}, {4.2, 0}, {4.25, -15},
{4.35,
1863}, {4.4, 1797}, {4.45, 7533}, {4.5, 0}, {4.55, 53}, {4.7,
12045}, {4.9, 7304}, {4.95, 34}};

list2 = {0.71, 3.2, 4, 4.5, 5};

index = Function[{what},
Module[{i = 0},
Catch[
If[# <= what, i++, Throw[i]] & /@ list2
]
]
]

ll1 = {#[[1]], #[[2]]*f[#[[1]]]} & /@ list1;

Plus @@@ Map[#[[2, 2]] &,
Split[{index[First[#]] , #} & /@ Sort[ll1, First[#1] < First[#2] &],
First[#1] == First[#2] &], {2}]

???

Regards
Jens

Guillermo Sanchez wrote:
>
> Dear group,
>
> I have two lists with this pattern
>
> list1={{a1 , b1}, ..., {ai , bi}, ...};
>
> list2={c1, ..., c(j-1),  cj, ...};
>
> and a function f[x] (ie: f[x_] = 0.2 x);
>
>
> I would like grouping and sum the product bi f[ai] where
> C(j-1)<ai< cj
>
>
> I show it with an example:
>
> list1 = {{0.71, 7378}, {1.6, 768}, {2, 2269}, {2.05, 0}, {2.35, 0},
> {2.4, 2608}, {2.6, 193}, {2.8, 4187}, {2.85, 204}, {2.95, 134},
> {3.2,776}, {3.25, 24}, {3.6, 6209}, {3.65, 0}, {3.7, 2809}, {3.95, 1923},
> {4,2627}, {4.1, 25}, {4.15, 1}, {4.2, 0}, {4.25, -15}, {4.35, 1863},
> {4.4, 1797}, {4.45, 7533}, {4.5, 0}, {4.55, 53}, {4.7, 12045}, {4.9, 7304},
> {4.95, 34}};
>
>
> list2 = {0.71, 3.2, 4, 4.5, 5}
>
>
> The solution should be:
>
> {{7378 f[0.71] + .. +134 f[2.95]}, ... , {53 f[4.55]+...+34 f[4.95]}}
>
> Thanks
>
> Guillermo

```

• Prev by Date: Re: trimming a string
• Next by Date: Re: trimming a string
• Previous by thread: Re: Programing operations with lists
• Next by thread: Re: Programing operations with lists