Re: modified list interval calculation
- To: mathgroup at smc.vnet.net
- Subject: [mg21221] Re: modified list interval calculation
- From: Pasquale Nardone <Pasquale.Nardone at ulb.ac.be>
- Date: Mon, 20 Dec 1999 02:27:43 -0500 (EST)
- Organization: Brussels Free Universities VUB/ULB
- References: <831tsm$fmj@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Deborah Leddon wrote: > Hi, > I am having trouble with the problem below: > > I am trying to remove from list, t, those numbers in list, nt, that > match and then I want to calculate the differences (intervals ) > between succesive numbers in list, t, that do not contain the > removed number. For example: > the two lists are; > t = {1,4,4.5,6,7,8,8.9,9,10,12,140,16,16.8,17,18, > 19,19.1,19.3,19.5,20} > nt = {8,8.9,10,17} > > the resulting intervals would look like: > 4 -1, 4.5 - 4, 6 - 4.5, 7 - 6, 140 -12, 16 - 140, 16.8 - 16, 19 - 18, > 19.1 -19, 19.3 - 19.1, 19.5 - 19.3, 20 - 19.5 > and of course the final list would be: > intervals = {3, .5, 1.5, 1, 128, -124, .8, 1, .1, .2, .2, .5}; > > Note that 9 was omitted from the calculation of intervals because it > would have been involved in a calculation with a removed number > from the list, t. > > Thanks in advance if anyone can help. > > Regards, Debbie try this one: First build a pairs of elements res = Drop[Transpose[{t, RotateLeft[t]}], -1] {{1, 4}, {4, 4.5}, {4.5, 6}, {6, 7}, {7, 8}, {8, 8.9}, {8.9, 9}, {9, 10}, {10,12}, {12, 140}, {140, 16}, {16, 16.8}, {16.8, 17}, {17, 18}, {18, 19}, {19, 19.1}, {19.1, 19.3}, {19.3, 19.5}, {19.5, 20}} Then rebuild a new list with elements extracted ListOut = {}; Do[ If[Intersection[res[[i]], nt] == {}, AppendTo[ListOut, res[[i]]]], {i, 1, Length[res]}] ListOut contains the corrected serie In[47]:= ListOut Out[47]= {{1, 4}, {4, 4.5}, {4.5, 6}, {6, 7}, {12, 140}, {140, 16}, {16, 16.8}, {18, 19}, {19, 19.1}, {19.1, 19.3}, {19.3, 19.5}, {19.5, 20}} Then apply the difference to that list: In[54]:= -Apply[Subtract, ListOut, 1] Out[54]= {3, 0.5, 1.5, 1, 128, -124, 0.8, 1, 0.1, 0.2, 0.2, 0.5} OR In[55]:= Map[#.{-1, 1} &, ListOut] Out[55]= {3, 0.5, 1.5, 1, 128, -124, 0.8, 1, 0.1, 0.2, 0.2, 0.5} OR In[59]:= Map[(#[[2]] - #[[1]]) &, ListOut] Out[59]= {3, 0.5, 1.5, 1, 128, -124, 0.8, 1, 0.1, 0.2, 0.2, 0.5} -------------------------------------------- Pasquale Nardone * Universite Libre de Bruxelles * CP 231, Sciences-Physique-Agrigation * Bld du Triomphe * 1050 Bruxelles, Belgium * tel: 650,55,15 fax: 650,57,67 (+32,2) * http://homepages.ulb.ac.be/~pnardon/ * --------------------------------------------