Re: Moving average type process
- To: mathgroup at smc.vnet.net
- Subject: [mg18295] Re: Moving average type process
- From: dreiss at earthlink.net (David Reiss)
- Date: Fri, 25 Jun 1999 15:05:35 -0400
- Organization: Scientific Arts
- References: <7kpbdq$4at@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
In article <7kpbdq$4at at smc.vnet.net>, Virgil Stokes <virgil.stokes at neuro.ki.se> wrote: > I wish to perform the following "moving average" type process on > a list to generate a new list: > > Inputs: > wtlist = {w1,w2,w3} -- weight list > inlist = {a,b,c,d,e,f} -- any other list (>= 3 elements) > > Output: > outlist = {w1*a+w2*b+w3*c, w1*b+w2*c+w3*d, w1*c+w2*d+w3*e, w1*d+w2*e+w3*f} > > Note, outlist will always contain 2 less (Length[wtlist]/2) elements > than in the input list (inlist). > > If w1=w2=w3=x, then > the following works fine: > > outlist = x*Drop[Plus@@NestList[RotateRight,inlist,2],2] > > This is a weighted (from wtlist) sum over another list of arbitrary > length (inlist). I would like to get a "fast" function for doing this when > the weights are not equal. > > -- Virgil Here is an example that should give you what you want along the lines of what you are trying above: In[1]:= Plus @@ ({w1, w1, w3}#) & /@ Partition[{a, b, c, d, e, f}, 3, 1] Out[1]= {a w1 + b w1 + c w3, b w1 + c w1 + d w3, c w1 + d w1 + e w3, d w1 + e w1 + f w3} In Mathematica Version 4 the ListConvolve function is the fastest way to do this, I believe. In[2]:= ListConvolve[{w1, w1, w3}, {a, b, c, d, e, f}] Out[2]= {b w1 + c w1 + a w3, c w1 + d w1 + b w3, d w1 + e w1 + c w3, e w1 + f w1 + d w3} Cheers, David -- )------------------------------------( ) Scientific Arts: ( ) Creative Services and Consultation ( ) for the Applied and Pure Sciences ( ) ( )--------------------------------------- ) http://www.scientificarts.com ) ) David Reiss ) Email: dreiss at !Spamscientificarts.com )---------------------------------------