MathGroup Archive 2000

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

Search the Archive

Re: functional routine for {a, b, c, ...} -> {a - b, b - c, c - ...a}

  • To: mathgroup at smc.vnet.net
  • Subject: [mg24907] Re: [mg24892] functional routine for {a, b, c, ...} -> {a - b, b - c, c - ...a}
  • From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
  • Date: Sun, 20 Aug 2000 01:34:56 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

I see nothing wrong with using ListCorrelate but here is another way:

In[4]:=
Drop[lst - RotateLeft[lst], -1]
Out[4]=
{a - b, b - c, c - d, d - e, e - f, f - g, g - h}


Andrzej

on 8/19/00 10:46 AM, Maarten.vanderBurgt at icos.be at
Maarten.vanderBurgt at icos.be wrote:

> Hallo,
> 
> element.
> I found two ways for doing this:
> 
> lst = {a, b, c, d, e, f, g, h};
> 
> Table[lst[[i]] - lst[[i + 1]], {i, 1, Length[lst] - 1}]
> {a - b, b - c, c - d, d - e, e - f, f - g, g - h}
> 
> ListCorrelate[{1, -1}, lst]
> {a - b, b - c, c - d, d - e, e - f, f - g, g - h}
> 
> The first method is rather clumsy and the 2nd one is quite short, but not
> really obvious.
> Initally I was looking for a functional programming style routine.
> Something like: (#[[i]]-#[[i-1]])&/@lst.
> Who can tell me how to do this in a functional programming style?
> 
> Thanks
> 
> Maarten van der Burgt
> Leuven, Belgium
> 
> 
> 
> 



  • Prev by Date: Re: Initializing subscripted variables
  • Next by Date: Re: How to get two values from a file into two lists?
  • Previous by thread: Re: Expanding a nested structure (pattern matching?)[Correction]
  • Next by thread: Re: Re: functional routine for {a, b, c, ...} -> {a - b, b - c, c - ...a}