I am a new Mathematica user, learning the intricacies of functional programming. I have issues withe applying a function over a moving list. My function seems to work and give correct results but it also shows a syntax error. Can you advise how I can get rid of the syntax errors?
movingMap[f_, mylist_, args_, r_] :=
ListConvolve[ConstantArray[1, r], mylist, {-1, 1}, {}, Times, f &];
yalist = {a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10};
testfunction[x_, y_, z_, w_] := w/6*(x + 4 y + z);
movingMap[testfunction[##, 1], yalist, t, 3]
This gives me the correct results but also gives a syntax warning.
{1/6 (a0 + 4 a1 + a2), 1/6 (a1 + 4 a2 + a3), 1/6 (a2 + 4 a3 + a4), 1/6 (a3 + 4 a4 + a5), 1/6 (a4 + 4 a5 + a6), 1/6 (a5 + 4 a6 + a7), 1/6 (a6 + 4 a7 + a8), 1/6 (a7 + 4 a8 + a9), 1/6 (a10 + a8 + 4 a9)}
I would appreciate advice on getting rid of the syntax error.
&from withinmovingMaptotestfunction[##,1]&. The simple reason: you can pass in functions using their heads alone that way, e.g. definetf[x__] := testfunction[x]and runmovingMap[tf, yalist,t,3]. – rcollyer Mar 12 at 20:27