Question: How do I create a function for this?

Hi everyone,

I'm trying to create a function that utilizes the index of a vector to preform the following:


Where x and y are both nx1 vectors.  I've tried using summation to no avail, as you can see below: 

Of course, it works when I do it this way, but it's incredibly inefficient if the vectors have a large number of rows:


Any help y'all can give me would be extremely appreciated!  Thank you kindly

Please Wait...