dot

Dot product of two vectors.

Category: Mathematics > Linear Algebra

Syntax

c = dot(A, B)

Returns the sum of the products of corresponding elements, conjugating A first.

c = dot(A, B, dim)

Works along the dimension dim for arrays.

Description

For real vectors the dot product equals A(:)'*B(:) and measures how much the vectors point in the same direction: it is zero for perpendicular vectors, and dot(A,A) is the squared length of A.

For complex inputs the first argument is conjugated, so dot(A,A) is always real and non-negative.

Input arguments

A, B
Vectors or arrays of the same size.
dim
Dimension along which to take the products (arrays only).

Output arguments

c
The scalar sum(conj(A).*B) for vectors.

Example

Real and complex vectors

dot([1 2 3], [4 5 6])
dot([1 2], [-2 1])
dot([1+2i 3], [2 1i])
Output
ans = 32
ans = 0
ans = 2.0000 - 1.0000i

See also

cross mtimes norm sum kron