dot product for complex vector

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

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
Stephen23
Stephen23 ungefär 11 timmar ago
Edited: Stephen23 ungefär en timme ago
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)
ans = 7.0000 -17.0000i
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)
ans = 1.0000 - 5.0000i
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."

Sign in to comment.

 Accepted Answer

John D'Errico
John D'Errico on 16 Jun 2019
Edited: Walter Roberson ungefär 4 timmar ago
help dot
dot Vector dot product.
C = dot(A,B) returns the scalar product of the vectors A and B.
A and B must be vectors of the same length. When A and B are both
column vectors, dot(A,B) is the same as A'*B.
dot(A,B), for N-D arrays A and B, returns the scalar product
along the first non-singleton dimension of A and B. A and B must
have the same size.
So what are A and B?
A = [1+i 1-i -1+i -1-i];
B = [3-4i 6-2i 1+2i 4+3i];
They are row vectors, complex row vectors. So MATLAB forms the result as:
dot(A,B)
ans =
1 - 5i
sum(conj(A).*B)
ans =
1 - 5i
That is, when A and B are both vectors, MATLAB treats them the same as if A and B were column vectors. It effectively thinks of them as both column vectors. Then it forms the result by conjugating A, takes an element-wise product, then sums those terms.

3 Comments

Hallo:
I think this is a mistake. If the dot function is intended to perform the dot product of two vectors, it should not perform any conjugate of any of the two vectors. This is misleading.
I agree with Charles
dot(A,B) should be equal to A(1)*B(1)+A(2)*B(2)+A(3)*B(3)+A(4)*B(4).
No matter if they are row or column vectors.
James Tursa
James Tursa ungefär 19 timmar ago
Edited: James Tursa ungefär 19 timmar ago
"... it should not perform any conjugate of any of the two vectors ..."
Where did you get this notion? Pretty much any online search for dot product of complex vectors involves a Hermitian form, conjugating either the first or second vector depending on which source you use.
Stephen23
Stephen23 ungefär 5 timmar ago
Edited: Stephen23 ungefär 5 timmar ago
"I think this is a mistake. If the dot function is intended to perform the dot product of two vectors, it should not perform any conjugate of any of the two vectors."
The Positive-Definiteness Axiom
The defining axioms of an inner product are not arbitrary — they are carefully chosen to give vector spaces the geometric structure we need (lengths, angles, orthogonality). One of those axioms is positive-definiteness, which states:
⟨v, v⟩ ≥ 0 for all vectors v, and ⟨v, v⟩ = 0 if and only if v = 0.
This is formally stated as: "For any u ∈ V, ⟨u, u⟩ ≥ 0; and ⟨u, u⟩ = 0 if and only if u = 0." source: Mathphysicsbook
This axiom is what allows us to define the norm (i.e. the length) of a vector as ‖v‖ = √⟨v, v⟩. Axiom P5 guarantees that ⟨v, v⟩ ≥ 0, so ‖v‖ is a real number (source: Physics Forums) If ⟨v, v⟩ could be complex or negative, taking a square root would yield an imaginary or undefined "length," which would make the entire geometric framework collapse.
Why Conjugation is Necessary to Satisfy This Axiom
Now consider what happens with a complex vector like v = [1+i]. Without conjugation, the "inner product" of this vector with itself would be:
(1+i)(1+i) = 1 + 2i − 1 = 2i !!!!
That is purely imaginary — not real, and certainly not non-negative. The positive-definiteness axiom is immediately violated.
With conjugation, we instead compute:
conj(1+i) · (1+i) = (1−i)(1+i) = 1 + 1 = 2
This is real and non-negative, as required.
The positive-definiteness condition ensures that the inner product of any non-zero vector with itself yields a non-negative real number, and the only way for this inner product to be zero is if the vector itself is the zero vector. This attribute guarantees that the concept of length (or norm) is meaningful. For complex vector spaces, conjugation is not optional decoration, it is the only way to simultaneously satisfy both the symmetry and positive-definiteness axioms.
The most important inner product spaces are those which are complete with respect to this metric; they are called Hilbert spaces (see Wolfram MathWorld). The entire edifice of Hilbert space theory (which underpins quantum mechanics, signal processing, and functional analysis) rests on positive-definiteness holding. Dropping conjugation would mean none of those results could be guaranteed.
Which is exactly why the DOT documentation states "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."

Sign in to comment.

More Answers (0)

Products

Release

R2018b

Asked:

on 16 Jun 2019

Edited:

ungefär en timme ago

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!