Written and maintained by CASRAI Editorial Board
Published
On this page
To compute the inner product of two vectors in MATLAB, use dot(A,B). For column vectors of the same length, A'*B returns the same value. Both conjugate the first argument when the data are complex, so the order of the arguments matters. This guide shows the syntax, a worked real and complex example, and how dot differs from the other ways of writing a product of two vectors. Sources were read on 2026-11-08.
What the inner product is used for in research
The inner product (the “matlab inner product” of two vectors) is the sum of the products of corresponding elements. Analysts use it to measure how aligned two signals or feature vectors are, to compute projections, and as the building block of norms and least-squares calculations. With complex data, such as Fourier coefficients, the definition includes a conjugate, which is why a plain element-wise sum of products is not always the right quantity.
Install or access
dot is a built-in MATLAB function. The reference page is MathWorks’ dot documentation. MATLAB is a MathWorks product; GNU Octave and Python with NumPy are free alternatives listed below.
Step-by-step: compute an inner product with dot
- Define two vectors of the same length. The documentation states that if
AandBare vectors, they must have the same length. Inputs must be numericsingleordouble; complex values are supported. - Call
C = dot(A,B). For arrays,C = dot(A,B,dim)evaluates along dimensiondim, a positive integer scalar. By default it uses the first dimension whose size is not 1. - Read the result. Example from the MathWorks page:
A = [4 -1 2]; B = [2 -2 -1]; C = dot(A,B)returns8, because 4×2 + (−1)×(−2) + 2×(−1) = 8.
Worked complex example
Take a = [1+2i; 3+4i] and b = [5+6i; 7+8i]. Because dot conjugates its first argument, dot(a,b) equals sum(conj(a).*b): (1−2i)(5+6i) = 17−4i, plus (3−4i)(7+8i) = 53−4i, giving 70 - 8i. Swapping the arguments gives dot(b,a) = 70 + 8i, the complex conjugate. The same numbers appear in the NumPy vdot documentation. The MathWorks page notes that dot(u,v) is the conjugate of dot(v,u), and that the dot product of a complex vector with itself is real and positive: dot(a,a) is 30 here (5 + 25).
Output and how to read it
- Two vectors give a scalar.
- Two matrices of the same size give one inner product per column by default (
dot(A,B)) or per row withdot(A,B,2). - If
dimis greater thanndims(A), the result isconj(A).*Bwith no summation. - For complex input, expect a complex value whose imaginary part changes sign when you swap the arguments.
dot(A,B) versus A’*B, A.’*B and sum(A.*B)
MATLAB’s operator table defines ' as the complex conjugate transpose, .' as the transpose, * as matrix multiplication and .* as element-wise multiplication. Combined with the dot definition, this gives the following for column vectors A and B of equal length.
| Expression | Conjugates A? | What it computes |
|---|---|---|
dot(A,B) |
Yes | Inner product; matches sum(conj(A).*B) for vectors (MathWorks dot page) |
A'*B |
Yes | Conjugate transpose times B: the same inner product for column vectors (operator table) |
A.'*B |
No | Plain transpose times B: a non-conjugated sum of products (derived from the operator table) |
sum(A.*B) |
No | Element-wise product, then sum: non-conjugated |
For real data all four give the same number. For complex data, use dot or A'*B when you want the mathematical inner product, and the non-conjugated forms only when you specifically want a bilinear product. For matrix products in general, see matrix multiplication in MATLAB; the transpose guide explains ' versus .'; for the vector product that returns a vector rather than a scalar, see cross product in MATLAB.
Troubleshooting
- Dimension errors.
dotrequires inputs of the same length (vectors) or size (arrays). Checksize(A)andsize(B).A'*Bneeds two column vectors; for two row vectors writeA*B'. - Unexpected imaginary sign. The first argument is the one conjugated. Reversing the arguments conjugates the result.
- Wrong dimension summed. For matrices the default is the first non-singleton dimension (columns). Pass
dim = 2for row-wise results. - Unsupported types. Inputs must be
singleordouble. Per the documentation, sparse inputs are not supported in C/C++ and GPU code generation.
Free alternatives
| Tool | Function | Behavior stated in its documentation |
|---|---|---|
| GNU Octave | dot (x, y), dot (x, y, dim) |
First argument conjugated; equivalent to sum (conj (X) .* Y, dim) |
| Python / NumPy | numpy.vdot(a, b) |
First argument conjugated if complex; flattens inputs to 1-D and does not perform a matrix product |
FAQ
What is the inner product in MATLAB?
It is dot(A,B): the sum of conj(A).*B for vectors, a scalar for two vectors of equal length.
Is the MATLAB inner product the same as A’*B?
For column vectors, yes. Both conjugate the first vector. A.'*B and sum(A.*B) do not.
Is dot(A,B) the same as dot(B,A)?
Only for real data. For complex data dot(A,B) is the conjugate of dot(B,A).







