MathGroup Archive 2003

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

Search the Archive

Re: nth differences


Zachary Turner wrote:
> Say I have a list of k integers and I want to produce a list containing the
> first differences?  For example, given {1, 2, 5, 7, 8, 9} the first
> differences are {1, 3, 2, 1, 1}, and the second differences are {2, -1, -1,
> 0}, the third are {-3, 0, 1}, etc
> 

Differences[A_List] := Drop[A, 1] - Drop[A, -1];


NestList[Differences[#] &, {1, 2, 5, 7, 8, 9}, 3]

{{1, 2, 5, 7, 8, 9}, {1, 3, 2, 1, 1}, {2, -1, -1, 0}, {-3, 0, 1}}


Differences[{1, 2, 5, 7, 8, 9}]

{1, 3, 2, 1, 1}


--Ed Pegg Jr



  • Prev by Date: Re: nth differences
  • Next by Date: Re: nth differences
  • Previous by thread: Re: nth differences
  • Next by thread: Re: nth differences