Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

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

Search the Archive

Re: Map and functional constructs to replace iterative statements

  • To: mathgroup at smc.vnet.net
  • Subject: [mg96831] Re: Map and functional constructs to replace iterative statements
  • From: dh <dh at metrohm.com>
  • Date: Thu, 26 Feb 2009 07:51:12 -0500 (EST)
  • References: <go31ba$f47$1@smc.vnet.net>


Hi Andreas,

there are several solutions, but I think the  most elegant is using 

vectors. E.g. assuming your data is in "d"

100 (Rest[d]-Most[d])/Most[d]

hope this helps, Daniel



Andreas wrote:

> I have begun to replace Table, Do, While, or For, but in my thinking with Map, Inner, Outer and other functional programming constructs as I learn more about Mathematica.

> 

> But, I'm stuck.  I need to figure out how to use Map (or some related approach) when a function needs both a current value and a previous value in a time series, such as a percentage change function (or perhaps more generally stated, when I need to refer to previous values in a series or even previous calculations).  But first a simple case:

> 

> percentChange[currentValue_, previousValue_] := 100 * ( currentValue - previousValue) / previousValue

> 

> I know how to apply this iteratively, but how can I do it with Map or some other functional construct?

> 

> Say I have a list: timeSeries 

> 

> I thought to try something like this:

> 

> Map[percentChange[?,?], timeSeries] 

> 

> but I don't know how what to put in for "?".

> 

> Any help much appreciated.

> 

> Thx.

> 




  • Prev by Date: Re: HoldForm[1*2*3] should give 1 x 2 x 3 not 2 x 3
  • Next by Date: Re: Need some help with monitoring evaluation
  • Previous by thread: Re: Map and functional constructs to replace iterative
  • Next by thread: Re: Map and functional constructs to replace iterative statements