5
$\begingroup$

What is the scalar product operator for complex vectors (or matrices) in Mathematica? The usual $Dot[]$ doesn't work. E.g. here is what the Mathematica gives $$\{1,0\}.\{I,0\}=I$$ but the answer should be $-I$, since the scalar product of complex vectors is defined as follows: let $$a,b∈C^n \,\,\, then \,\,(a,b)= ∑_{i=1}^na_i \bar b_i$$ where $\bar b_i$ is the complex conjugate of $b_i$.

$\endgroup$
0

2 Answers 2

6
$\begingroup$

You can define your own scalar product as

Scalar[a_, b_] := Dot[a, Conjugate[b]]

so that Scalar[{1,0},{I,0}] = -I. The issue is that vectors and dual vectors in Mathematica are written the same way---they are both lists---so the system has no way to keep track of whether you are passing it b or Conjugate[b], for example. Thus Mathematica does the least surprising thing, which is to assume Dot[a,b]==Dot[b,a], and not Dot[a,b]==Conjugate[Dot[b,a]].

Edit: if you need the canonical scalar matrix product, you can use these definitions instead:

Scalar[a_, b_] :=  Dot[a, Conjugate[b]] /; Length[Dimensions[a]] == Length[Dimensions[b]] == 1
Scalar[a_, b_] :=  Tr[Dot[a, ConjugateTranspose[b]]] /; And[
     Length[Dimensions[a]] == Length[Dimensions[b]] == 2,
     Dimensions[b] == Dimensions[a]
     ]

so that the example above still holds, but you can, for example, do

Outer[Scalar, PauliMatrix /@ Range[0, 3], PauliMatrix /@ Range[0, 3],1]

which gives 2 IdentityMatrix[4] as expected.

$\endgroup$
5
  • $\begingroup$ You can, of course, invent your own mathematics. With Mathematica it's also easy to overload the Plus-operator to get any desired result (like 1 + 1 = 3). $\endgroup$
    – eldo
    Commented Jun 18, 2014 at 18:17
  • $\begingroup$ @eldo I don't know if a link to Wikipedia is good enough, but please know that the dot product on complex vectors can be so defined. en.wikipedia.org/wiki/Dot_product#Complex_vectors $\endgroup$
    – evanb
    Commented Jun 18, 2014 at 18:20
  • $\begingroup$ And I don't understand the downvote, either. $\endgroup$
    – evanb
    Commented Jun 18, 2014 at 18:21
  • 1
    $\begingroup$ Note that the definition there reduces to the familiar definition if a and b are real. When someone says they have a complex number, they typically mean that they have a number that lives in the complex plane. That number might accidentally be real, in which case the complex conjugate doesn't do anything. But for not-accidentally-real complex numbers, the conjugate matters. $\endgroup$
    – evanb
    Commented Jun 18, 2014 at 18:34
  • 1
    $\begingroup$ the downvote was because of the slightly arrogant "People are simply talking past one another in the other answers." Now you know the reason and I upvote again :) $\endgroup$
    – eldo
    Commented Jun 18, 2014 at 18:34
0
$\begingroup$

That is how you do a dot product in Mathematica.You have the wrong symbol but in this case Mathematica still gave you correct answer:

{1,0}.{I,0}=1*I+0*0=I
$\endgroup$
1
  • $\begingroup$ your answer works in this simple case, but it is not the definition of the dot product for complex vectors. $\endgroup$
    – eldo
    Commented Jun 18, 2014 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.