Re: List manipulation question
- To: mathgroup at smc.vnet.net
- Subject: [mg67195] Re: [mg67163] List manipulation question
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Sun, 11 Jun 2006 23:08:02 -0400 (EDT)
- Reply-to: hanlonr at cox.net
- Sender: owner-wri-mathgroup at wolfram.com
dif[x_?VectorQ]:=Join[{x[[2]]-x[[1]]},
ListConvolve[{1/2,0,-1/2},x],
{x[[-1]]-x[[-2]]}];
list={x1,x2,x3,x4};
dif[list]
{x2 - x1, x3/2 - x1/2, x4/2 - x2/2, x4 - x3}
list={3700,3800,3900,3950,4000,
4050,4100,4150,4200,4250,
4300,4350,4400,4450,4500,
4550,4600,4650};
dif[list]
{100,100,75,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50}
Bob Hanlon
---- LectorZ <lectorz at mail.ru> wrote:
> Dear experts,
>
> I need to calculate distances between the elements of the following
> list:
>
> list={3700, 3800, 3900, 3950, 4000, 4050, 4100, 4150, 4200, 4250, 4300,
> 4350,
> 4400, 4450, 4500, 4550, 4600, 4650}
>
> with the following logic:
>
> a) If it is the first element, then take the simple difference to the
> next (i.e. 3800 - 3700)
> b) If it is the last element, then take the simple difference to the
> second last (i.e. 4650 -4600)
> c) the difference for all elements in between shoud be calculated as
> (next - last)/2 (i.e. (3900 - 3700)/2)
>
> This list should come out as a result:
>
> result={100,100,75,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50}
>
> Thanks a lot for your help
>
> LZ
>