Skip to main content
v2026.11,986 entries · CC-BY 4.0

Inner Product in MATLAB: dot(), A’*B and Complex Vectors

Compute a MATLAB inner product with dot(A,B), see why complex vectors conjugate the first argument, and compare dot with A’*B.

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

  1. Define two vectors of the same length. The documentation states that if A and B are vectors, they must have the same length. Inputs must be numeric single or double; complex values are supported.
  2. Call C = dot(A,B). For arrays, C = dot(A,B,dim) evaluates along dimension dim, a positive integer scalar. By default it uses the first dimension whose size is not 1.
  3. Read the result. Example from the MathWorks page: A = [4 -1 2]; B = [2 -2 -1]; C = dot(A,B) returns 8, 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 with dot(A,B,2).
  • If dim is greater than ndims(A), the result is conj(A).*B with 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. dot requires inputs of the same length (vectors) or size (arrays). Check size(A) and size(B). A'*B needs two column vectors; for two row vectors write A*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 = 2 for row-wise results.
  • Unsupported types. Inputs must be single or double. 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).

Sources

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Inner Product in MATLAB: dot(), A’*B and Complex Vectors

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →