In these last two functions, the number of data points is found by summing the elements of the
frequency list.
[6.43] Dot product (scalar product) for complex vectors
The built-in dotp() function can be used to find the scalar dot product for two complex vectors, but its
behavior may be puzzling. The vector dot product of a and b is defined as
[1]
a $ b =
æ
a
æ
2
æ
b
æ
2
cos
(
✕
)
where θ is the angle between the two vectors, and
æ
a
æ
2
=
✟
i=1
n
a
i
2
which is the L
2
(Euclidean) norm. Suppose that we want to find the dot product of a vector and itself, or
a $ a =
æ
a
æ
2
æ
a
æ
2
cos
(
✕
)
=
æ
a
æ
2
2
cos
(
0
)
=
æ
a
æ
2
2
In other words, the dot product of a vector with itself must be real and non-negative. dotp() correctly
returns this result. Some users claim that the 89/92+ calculate this function in error, and that the
complex conjugate of the second argument must be taken, to get the 'correct' result. However,
suppose we apply this technique to the vector [1+i, 1+i], where 'i' is the square root of -1. Then
dotp([1+i],[1+i]) = 4
as expected, but
dotp([1+i],conj([1+i])) = 4i
which must be wrong, because the result must be real and non-negative. Some of this confusion may
result because there are actually two working definitions of dot product. In linear algebra, optimization
and computer science, the inner product is defined as
[2]
x
T
y =
✟
i=1
n
x
i
$ y
i
While this definition provides consistent results in real linear algebra and optimization, it cannot be
used for the complex vector dot product, because it fails in the case of finding the dot product of a
vector with itself.
For real-valued vectors, there is no ambiguity, and dotp() returns the correct results. Note also that
dotp() can accept lists as arguments, and for complex elements it also implicitly uses the definition in
[1] above, not [2].
(Credit to Bhuvanesh Bhatt and Fabrizio)
6 - 77