0
$\begingroup$

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.

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

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}]

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.