Group Abstract Group Abstract

Message Boards Message Boards

0
|
30.9K Views
|
21 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Get the Dot product of two vectors with complex components?

I am trying to obtain the scalar product of two vectors whose components are complex valued. I can do the maths (as I understand it) by hand for my first simple examples but struggle with Mathematica 11. The simplest task which is to establish the Norm of these vectors works fine, but when I then try to get the Dot product, I get an error from Mathematica. I am sure that I have the syntax wrong somewhere or that I need to use the INNER function rather than Dot but I cannot get that to work either based on my reading of the Mathematica Help. I have attached a very simple Notebook to illustrate my problem.

Any help will be gratefully received.

Thanks David

Attachments:
POSTED BY: David Mackay
21 Replies
Posted 2 years ago

Example:

p = {a, I b};
q = {c, I d};

In[3]:= p . q
Out[3]= a c - b d

Another:

z = {I 3, I 4};
u = {I 5, I 6};

In[6]:= z . u
Out[6]= -39
POSTED BY: Hans Milton

Again, we have had this issue in our Math-classes. They explained us that there are two definitions of the inner product of complex vectors:

  • mathematical definition: a.b = Conjugate[a].b
  • Definition used by physicists: a.b=a.Conjugate[b]

BUT there is no definition for an inner product of complex vectors without a conjugate.

In my eyes, Mathematica should provide us

  • with the Dot-function calculating the correct inner product with the mathematician-definition; AND
  • a special function for calculating the inner product according to the physicists-definition.

Best Regals,

JJJ

POSTED BY: Joachim Janezic

Dot computes the standard dot product (a tensor contraction). It is not an inner product in the mathematical sense. This is noted in Possible Issues in the reference guide page for Dot.

Also it is by design. For one, we do not want a complicated mess emerging from symbolic dot products. More importantly, Dot is a general function that takes multiple arguments and allows for tensors of arbitrary rank (subject to dimensional compatibility requirements of neighboring arguments). The Hermitian inner product is a far more specialized beast, and what it requires does not extend to Dot.

The Scope section of documentation has at least one example of computing as a Hermitian inner product. Likewise, in the ref guide page of Inner there is an example of this.

POSTED BY: Daniel Lichtblau

Daniel @Daniel Lichtblau,

I see you added this issue in the documentation several years ago under "Possible Issues" - Thank you. The problem I see is that many engineers do not understand what a "Hermitian inner product" is. I had to look it up since that term was unfamiliar to me. Can you expand that section of the documentation a bit to also say that issue applies to complex vector math?

It would also be helpful to have a statement about this issue in the Details section that links to the Possible Issues because Dot is so frequently used for complex vector space operations.

Regards,

Neil

POSTED BY: Neil Singer
POSTED BY: Daniel Lichtblau

4 years after your initial discussion, there is still no warning flag in the reference that the Dot-product for complex vectors does not match the mathematical definition. There is one very small hint in the definition of the Norm under "Properties & Relationships". It was one full afternoon to discover that there is (in my eyes) a bug in Mathematica.

POSTED BY: Joachim Janezic

Thank you, Daniel.

That is helpful.

POSTED BY: Neil Singer
POSTED BY: Neil Singer

If mat1 is a 1x3 complex-valued matrix, mat2 is 3x3, and mat3 is 3x1, what part(s) would be conjugated in taking the product mat1.mat2.mat3?

The fact that Dot does not do conjugation will be mentioned under "Possible Issues" in the reference page for Dot, as of the next release. Likewise there will be an example of using Inner to get the scalar product of vectors in C^n, I believe under the "Scope" section on the page for Inner.

POSTED BY: Daniel Lichtblau

To respond to the issue of complex conjugation, Dot is doing what it was designed to do. It operates on general tensors and, more importantly, is vararg (in other words, not restricted to two arguments). The scalar product under discussion above, in contrast, has arity 2, that is, must have exactly two arguments.

To get the Hermitian inner product one can use Inner, as below.

aa = {1 + I, 3 - I, -5 + 7*I};
bb = {-2, -3 - I, 6*I};
Inner[#1*Conjugate[#2] &, aa, bb, Plus]

There is an open suggestion that this be documented better. I'll add a note referencing this Community thread.

(* Out[1705]= 32 + 34 I *)
POSTED BY: Daniel Lichtblau

Tech Support confirmed the issue. They said they were filing "a report with our developers for them to generalize the Dot function to be able to handle complex vectors".

I don't know which version they plan on implementing -- It seems most people agree that it should be Conjugate[a].b (Like Matlab). Is the Wikipedia article simply wrong? Maybe I should just edit it and fix it??

POSTED BY: Neil Singer
Posted 8 years ago

My earlier response referred to C rather that Cn, so I have edited it out.

Some good material on complex vector spaces can be found at: Complex Vector Spaces

POSTED BY: David Keith

Perhaps theoretical physicists use a different definition than what I was taught in linear algebra classes. However, the two definitions are just conjugate of each other. As for Mathematica's Dot function, the documentation should address this issue, because it leads to confusion. The Dot function does tensor index contraction without introducing any conjugation. There is no built-in function for the Hermitian inner product of complex vectors. The Norm function does what we would expect in the complex case too, but using Abs, not Conjugate.

POSTED BY: Gianluca Gorni

Hello Neil,

My source for the definition the scalar product when either vector has complex components is a text 'Mathematical Methods in the Physical Sciences', by M. L. Boas 3rd Ed 2006. I will also go back to my old Morse and Feshbach 'Methods of Theoretical Physics' and see whether or not they offer a view.

POSTED BY: Gianluca Gorni

Hello Neil,

My source for the definition the scalar product when either vector has complex components is a text 'Mathematical Methods in the Physical Sciences', by M. L. Boas 3rd Ed 2006. I will also go back to my old Morse and Feshbach 'Methods of Theoretical Physics' and see whether or not they offer a view.

POSTED BY: David Mackay
POSTED BY: Neil Singer
Posted 8 years ago

I see your point. Mathematica implements the dot product in the usual way, even for complex numbers. Which is not suitable as an inner product over a complex vector space. I don't know if there is a built in function for this, but you can implement your own:

complexInner[a_, b_] := Conjugate[a].b

This conjugates the first argument; you could in the same manner conjugate the second argument instead.

Best, David

POSTED BY: David Keith
POSTED BY: David Mackay

David, Gianluca,

Thank you both for pointing out my list structure error. My Notebook now executes without error messages, but I am not getting the results that I expected. In my new attachment, the Mathematica Dot function gives one result whereas the 'longhand' version gives the answer that I derive by hand. I am taking my definition of the vector dot product for (3D) complex component vectors to be:

A.B = Sum (from i=1,3) A*[i]B[i] as in my longhand version.

It maybe that I am using the wrong definition for the Dot product when the components are complex. I shall dig deeper tomorrow.

Again, thank you for your prompt replies.

Attachments:
POSTED BY: David Mackay
POSTED BY: Gianluca Gorni
Posted 8 years ago

Hi David, Throughout your notebook you are inclosing each complex number in its own bracket. This turns your vectors into matrices. Here is how to take the dot product of vectors:

In[1]:= {1 + 2 I}.{2 + 3 I}

Out[1]= -4 + 7 I
POSTED BY: David Keith
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard