# Simple convolution

I have two lists, x and y, each of length Nx. I'm trying to create a function that gives the cross correlation at lag n. My attempt thus far is as follows:

Rxy[n_]=Sum[x[[m]]*y[[m + n]], {m, 1, Nx - n}]


The error message I receive states:

"The expression m cannot be used as a part specification." "The expression m+n cannot be used as a part specification."

This should be a simple function to construct and could perhaps be done with List Convolve, but I can't understand the nature of the error message.

• Use SetDelayed (:=) instead of Set (=), that is: Rxy[n_]:=Sum...... – corey979 Dec 7 '17 at 23:20

Use SetDelayed (:=) so that it isn't evaluated immediately, but rather calculated each time it is called:
Rxy[n_] := Sum[x[[m]]*y[[m + n]], {m, 1, Nx - n}]