RE: ListConvolve?
- To: mathgroup at smc.vnet.net
- Subject: [mg42451] RE: [mg42437] ListConvolve?
- From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
- Date: Wed, 9 Jul 2003 08:24:26 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
>-----Original Message----- >From: guillerm at usal.es [mailto:guillerm at usal.es] To: mathgroup at smc.vnet.net >Sent: Tuesday, July 08, 2003 10:37 AM >To: mathgroup at smc.vnet.net >Subject: [mg42451] [mg42437] ListConvolve? > >I have two lists: > days = {t1, t2, t3}; > retention = {f[b0, c0, t], f[ b1, c1, t], f[b2, c2, t]}; > >I wish obtain this output: > > {f[b0, c0, t1], f[b0, c0, t2] + f[b1, c1, t1] , > f[b0, c0, t3] + f[b1, c1, t2] + f[b2, c2, t1] } // TableForm > >I have obtained a solution but it is not efficient and my lists are >already large (here are only examples). Any help? > > >Guillermo two similar suggestions (depends a little on your freedom to add definitions to f): In[3]:= bb = {b0, b1, b2}; cc = {c0, c1, c2}; (1) In[5]:= ClearAll[f, g] In[6]:= f[__, Null] = 0; (if you may do so, but you may choose another tag instead of Null) In[7]:= g /: f[g[s__], t_] := f[s, t] (g is just a container to pass the sequence) In[8]:= ListConvolve[MapThread[g, {bb, cc}], days, {1, 1}, Null, f] Out[8]= {f[b0, c0, t1], f[b0, c0, t2] + f[b1, c1, t1], f[b0, c0, t3] + f[b1, c1, t2] + f[b2, c2, t1]} (2) In[10]:= ClearAll[f, g] In[11]:= f /: Join[f[_, _], Null] = 0; (f[b, c] must not evaluate here, but only upvalues are added to f) In[12]:= ListConvolve[MapThread[f, {bb, cc}], f /@ days, {1, 1}, Null, Join] Out[12]= {f[b0, c0, t1], f[b0, c0, t2] + f[b1, c1, t1], f[b0, c0, t3] + f[b1, c1, t2] + f[b2, c2, t1]} -- Hartmut Wolf