dot product for complex vector
Show older comments
Hello,
In the Matlab example, you have the dot product of the following two vectors A and B and its answer is vector C.
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
However, when I calculate it, I have vector C = 7 - 17i
That is, I have C vector results as follows below
(1+i) * (3-4i) + (1-i) * (6-2i) + (-1+i) * (1+2i) + (-1-i) * (4+3i) =
(7-i) +( 4-8i) + (-3-i) + (-1-7i) =
7 - 17i.
Hence, could you please tell me how the Matlab got the results (or show me manually how Matlab got the dot product answer) as I have different results than Matlab calculated using dot product?
Thank you,
Charles
2 Comments
Alejandro Rodríguez-Gómez
on 27 Feb 2026 at 16:47
I fully agree with Charles.
This is a bug in the way dot function is defined for complex vectors.
It seems to work fine for real vectors, though...
Best,
Alejandro
This is not a bug, but it touches on an important distinction in linear algebra. James Tursa's comment points in the right direction, so lets look deeper...
There are actually two different operations being conflated here.
The standard arithmetic "sum of products" that Charles calculated (1+i)(3-4i) + (1-i)(6-2i) + ... = 7 - 17i is correct as a straightforward element-wise multiplication and sum. In MATLAB, you can get this result with sum(A.*B), lets try it right now:
A = [1+i, 1-i, -1+i, -1-i];
B = [3-4i, 6-2i, 1+2i, 4+3i];
sum(A.*B)
However, MATLAB's dot() function for complex vectors intentionally computes the Hermitian inner product (also called the complex inner product), which is defined as:
⟨A, B⟩ = Σ conj(Aᵢ) · Bᵢ
So MATLAB uses the mathematically standard definition of an inner product for complex vector spaces. The conjugation is essential because it ensures the inner product satisfies the property that ⟨A, A⟩ is always a real, non-negative number (specifically, the squared magnitude of the vector). Without conjugation, ⟨A, A⟩ could be complex or even zero for a non-zero vector, which would break the fundamental properties of an inner product space. So to directly answer the original question, MATLAB computed:
conj(1+i)(3-4i) + conj(1-i)(6-2i) + conj(-1+i)(1+2i) + conj(-1-i)(4+3i) = (1-i)(3-4i) + (1+i)(6-2i) + (-1-i)(1+2i) + (-1+i)(4+3i) = (3-4i-3i+4i²→ -1-7i) + ... = 1 - 5i ✓
dot(A,B)
Summary
- Use dot(A,B) when you want the true mathematical inner product (Hermitian form), which is the standard in mathematics for complex spaces.
- Use sum(A.*B) if you specifically want element-wise multiplication summed without any conjugation.
References
1. Wikipedia – Inner Product Space Wikipedia's article on Inner Product Spaces states that the inner product satisfies conjugate-linearity, noting: "This is how the inner product was originally defined and is used in most mathematical contexts". It also explains the importance of conjugation for ensuring the inner product is well-behaved, and notes that the alternative convention (linear in the second argument, conjugate-linear in the first) originates in the bra-ket notation of Paul Dirac and is used in physics and engineering.
2. Wolfram MathWorld – Inner Product MathWorld states that with the conjugation property, "the inner product is called a Hermitian inner product and a complex vector space with a Hermitian inner product is called a Hermitian inner product space", and that every inner product space is naturally also a normed space via the inner product.
3. Wolfram MathWorld – Hermitian Inner Product MathWorld's dedicated article on the Hermitian Inner Product defines it as "a complex-valued bilinear form on V which is antilinear in the second slot, and is positive definite", explicitly showing the role of complex conjugation in the standard formulation.
4. University of Maryland – Course Notes on Hermitian Inner Products A University of Maryland linear algebra supplement explicitly notes that the conjugate form "is the definition used by Matlab where the Hermitian inner product is calculated by dot(u,v)", directly connecting the mathematical standard to MATLAB's implementation.
5. ScienceDirect – Hermitian Inner Product Overview ScienceDirect's overview confirms that "a Hermitian inner product is a bilinear functional on a complex vector space" and that "the inner product is defined as the product of a column vector times a Hermitian positive-definite matrix times the conjugate transpose of the column vector."
Accepted Answer
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!