If A and B are
vectors, then they must have the same length.

If A and B are
matrices or multidimensional arrays, then they must have the same
size. In this case, the dot function treats A and B as
collections of vectors. The function calculates the dot product of
corresponding vectors along the first array dimension whose size does
not equal 1.

A = [1+i 1-i -1+i -1-i];
B = [3-4i 6-2i 1+2i 4+3i];

Calculate the dot product of A and B.

C = dot(A,B)

C =
1.0000 - 5.0000i

The result is a complex scalar since A and B are
complex. In general, the dot product of two complex vectors is also
complex. An exception is when you take the dot product of a complex
vector with itself.

Find the inner product of A with itself.

D = dot(A,A)

D =
8

The result is a real scalar. The inner product of a vector with
itself is related to the Euclidean length of the vector, norm(A).

The result, C, contains three separate dot
products. dot treats the columns of A and B as
vectors and calculates the dot product of corresponding columns. So,
for example, C(1) = 54 is the dot product of A(:,1) with B(:,1).

Find the dot product of A and B,
treating the rows as vectors.

D = dot(A,B,2)

D =
46
73
46

In this case, D(1) = 46 is the dot product
of A(1,:) with B(1,:).

Dimension to operate along, specified as a positive integer
scalar. If no value is specified, the default is the first array dimension
whose size does not equal 1.

Consider two 2-D input arrays, A and B:

dot(A,B,1) treats the columns
of A and B as vectors and returns
the dot products of corresponding columns.

dot(A,B,2) treats the rows of A and B as
vectors and returns the dot products of corresponding rows.

dot returns conj(A).*B if dim is
greater than ndims(A).

This relation is commutative for real vectors, such that dot(u,v) equals dot(v,u).
If the dot product is equal to zero, then u and v are
perpendicular.

For complex vectors, the dot product involves a complex conjugate.
This ensures that the inner product of any vector with itself is real
and positive definite.

When inputs A and B are
real or complex vectors, the dot function treats
them as column vectors and dot(A,B) is the same
as sum(conj(A).*B).

When the inputs are matrices or multidimensional arrays,
the dim argument determines which dimension the sum function
operates on. In this case, dot(A,B) is the same
as sum(conj(A).*B,dim).