       Re: Replace Table[Sum...]...] with Functional code

• To: mathgroup at smc.vnet.net
• Subject: [mg98551] Re: Replace Table[Sum...]...] with Functional code
• From: Ray Koopman <koopman at sfu.ca>
• Date: Sun, 12 Apr 2009 03:48:52 -0400 (EDT)
• References: <grn1l3\$n0t\$1@smc.vnet.net>

```On Apr 10, 1:57 am, Andreas <aa... at ix.netcom.com> wrote:
> I use the following two functions to analyze time series:
>
> mm[data_,period_] := Table[Sum[(Log[data[[t]]] - Log[data[[t-i]]])/
>    Sqrt[i], {i,1,period}] / period, {t, period+1, Length[data]}]
>
> mr[data_,period_] := Table[Sum[Log[data[[t-i]]/data[[-i + t-1]]] *
>   (Sqrt[i] - Sqrt[i-1]), {i,1,period}],{t, period+2, Length[data]}]
>
> They have a similar structure, Table[Sum[...]...], which sums a
> bunch of stuff from the time series at each point in the series.
>
> I'd like to convert them into functional programing constructs, but
> as the increments in the Table function come into play in the Sum,
> I haven't been able to figure out a way to do it.
>
> I've tried Map with Partition and a bunch of other things,
> but I could use some pointers.
>
> Any help much appreciated.

Here is a fourth version of mm. Why I transposed things in the third
version is beyond me! This one is both faster and more elegant.

mm[data_, period_] := Partition[Log@data,period+1,1].
(Append[-#,Tr@#]&[1/(Sqrt@Range[period,1,-1]*period)])

```

• Prev by Date: Re: Scaling JPEGs or TIFFs inside PDF slides (using Illustrator)?
• Next by Date: Re: Efficient construction of a correlation matrix
• Previous by thread: Replace Table[Sum...]...] with Functional code
• Next by thread: Re: Replace Table[Sum...]...] with Functional code