Re: List manipulation question
- To: mathgroup at smc.vnet.net
- Subject: [mg67219] Re: List manipulation question
- From: "Dana DeLouis" <ddelouis at bellsouth.net>
- Date: Tue, 13 Jun 2006 01:07:05 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Hi. Just another option would be to use Bob's excellent idea, and solve for the padded variables. Thus: dif[v_?VectorQ] := ListConvolve[ {1/2, 0, -(1/2)}, v, {2, -2}, {2*v[[-1]] - v[[-2]], 2*v[[1]] - v[[2]]}] v = {3700, 3800, 3900, 3950, 4000, 4050, 4100, 4150, 4200, 4250, 4300, 4350, 4400, 4450, 4500, 4550, 4600, 4650}; Your desired results: result = {100, 100, 75, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50}; dif[v] == result True -- HTH. :>) Dana DeLouis Windows XP, Mathematica 5.2 "LectorZ" <lectorz at mail.ru> wrote in message news:e6ge0k$nh3$1 at smc.vnet.net... > 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 should 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 >