How to take dot product of every element in a list?

I have a list of coordinates (coord):

{{59.1915, 42.0843}, {62.0695, 71.2996}, {48.4124, 52.1423},
{51.3325,60.8624}, {54.8544, 44.72}, {55.39, 63.9032},
{59.1566,67.2319}, {48.1271, 57.0733}, {63.0908, 76.0996},
{50.644, 47.5917}}

Using:

diffcoord = Differences[coord]

I can calculate the difference between consecutive coordinates:

{{2.87796, 29.2153}, {-13.6571, -19.1573}, {2.9201, 8.7201},
{3.52192, -16.1424}, {0.53561, 19.1832}, {3.76663, 3.32865},
{-11.0295, -10.1585}, {14.9637, 19.0262}, {-12.4468, -28.5079}}

Now, I want to calculate:

d = dx1*dx2 + dy1*dy2

for each pair of differenced coordinate in the list. where $dx_1 = x_2-x_1, dy_1=y_2-y_1$ (which is the first element of the diffcoord list)

I was trying to use Dotbut I found out that it's not going to do I want. Is there a command like Differences or Accumulate that does what I need.

I am trying to calculate the correlation between unit tangent vectors (uni-leipzig.de/~pwm/web/?section=introduction&page=polymers). To calculate unit tangent vector, I need to take the derivative of the curve at that point. Since it's cubic spline, I can't do so. I am trying to approximate it by (iiserpune.ac.in/~cathale/lects/bio322-phybio1/2013bio322/…) . Do you know of any better way to do it?

This question is a follow-up to this question: How to find a length of a curve constructed using Spline?

• Wait… did you want to take the dot product for the original list, or for the differenced one? In any event: Dot @@@ Partition[(* coordinates *), 2, 1]. May 15 '15 at 15:12
• Differenced ones. I Just added more info to get my point across. May 15 '15 at 15:14
• "Since it's cubic spline, I can't do so." - well, actually, you can. Here is a sketch: the routines I gave here for generating cubic B-splines ought to also work in 3D; having generated the parameter values and control points, you can then explicitly generate the component functions with a procedure similar to the one in this answer to generate the unit tangent vector. May 15 '15 at 16:31

Here's how I'd do it. Starting with diffcoord

diffcoord = {{2.87796, 29.2153}, {-13.6571, -19.1573}, {2.9201,
8.7201}, {3.52192, -16.1424}, {0.53561, 19.1832}, {3.76663,
3.32865}, {-11.0295, -10.1585}, {14.9637,
19.0262}, {-12.4468, -28.5079}};

Pair each element with the next and Dot the pairs.

Dot@@@(Transpose@{diffcoord[[1;;-2]],diffcoord[[2;;-1]]})

The output is

{-598.991, -206.934, -130.479, -307.777, 65.8716, -75.3581, -358.32,
-728.647}

There is certainly a more clever way to combine the two if you need to do this on huge lists, but this makes sense to me.

Edit: @Guess who it is reminded me that Partition has a 3rd argument to specify an offset, which makes this a lot nicer looking!

Dot@@@Partition[diffcoord,2,1]
• Would've used Partition[] myself… :) May 15 '15 at 16:35
• I am so new to Mathematica. I don't know much about it's power. @Guesswhoitis. your suggestion worked. However, I do not understand what Dot@@@ is doing. I am currently in the process of reading : mathprogramming-intro.org/download/MathProgrammingIntro.pdf .. I think I will get to Map in 3-4 days. May 15 '15 at 17:00
• @psimeson, a tip: everytime you encounter an unfamiliar function or operator, highlight it on the front end and press F1. In this case, you should be seeing the entry for Apply[] May 15 '15 at 17:07

You can use PartitionMap from Developer package, e.g.

lst = {{59.1915, 42.0843}, {62.0695, 71.2996}, {48.4124,
52.1423}, {51.3325, 60.8624}, {54.8544, 44.72}, {55.39,
63.9032}, {59.1566, 67.2319}, {48.1271, 57.0733}, {63.0908,
76.0996}, {50.644, 47.5917}};
Developer`PartitionMap[Dot @@ # &, Differences@lst, 2, 1]

yields:

{-598.991, -206.934, -130.479, -307.777, 65.8725, -75.3586, -358.323, \
-728.65}

A recent answer by Mr. Wizard brought this to my attention. I post in case others not aware.

Your wording is very ambiguous. You start with coordinates, then calculate the differences between successive points, and then claim you want to calculate dx1*dx2 + dxy*dy2 for each pair of coordinate [sic] in the list. Do you mean for each successive pair of two-element lists? Or the outer product, i.e., the differences between the each two-element list and every other two element list?