Group Abstract Group Abstract

Message Boards Message Boards

0
|
32.5K 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 3 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
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

@NeilSinger This will get looked at in an upcoming review of documentation for Dot and perhaps related linear algebra functions. I am optimistic that your suggestions will be seriously considered (read: no promises, but several of us think they make good sense).

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
POSTED BY: Neil Singer

Daniel,

I am not sure that is correct. On Matlab's site they give an example of a 4 dimensional complex dot product. The Mathematica result and the Matlab result are different. I believe that Matlab is correct. I may be missing something but the first line gives the Mathematica result and the second line gives the Matlab result. I would normally expect Mathematica to test for complex arguments and apply the definition given at the bottom of the Matlab website (as Matlab does). As the alternative they should discuss this in the documentation (as you suggest) (with an example?). Thank you.

In[1]:= Dot[{1 + I, 1 - I, -1 + I, -1 - I}, {3 - 4 I, 6 - 2 I, 
  1 + 2 I, 4 + 3 I}]

Out[1]= 7 - 17 I

In[2]:= Dot[
 Conjugate[{1 + I, 1 - I, -1 + I, -1 - I}], {3 - 4 I, 6 - 2 I, 
  1 + 2 I, 4 + 3 I}]

Out[2]= 1 - 5 I
POSTED BY: Neil Singer
POSTED BY: Daniel Lichtblau
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 9 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

David,

I think you found a bug. I've been burned by this in the past. I just reported this to wolfram -- Either Dot should work properly for complex numbers or Wolfram should note this in the documentation and say how to extend it for Complex numbers.

In researching this I am a bit confused -- maybe you Complex math gurus can help explain this. In Wikipedia it says the Complex dot product is a.Conjugate[b] but in Matlab's website it says its Conjugate[a].b. They are not the same (They are conjugates of each other). Which is correct?

Regards

POSTED BY: Neil Singer
Posted 9 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

Hi David,

Thanks again for your help. It just goes to show that it always pays to start with some really simple examples that can be checked by hand. All that ancient Fortran coding experience still pays off from time to time!

Cheers,

David

POSTED BY: David Mackay
Attachments:
POSTED BY: David Mackay

The way you write vectors, they become column matrices, for which the Dot product is inappropriate. You can work around it for example by transposing or flattening:

v1 = {{5 + 2 I}, {3 - I}, {1 + I}};
v2 = {{-6 - 3 I}, {4 + I}, {5 - 7 I}};
Transpose[v1].v2
Flatten[v1].Flatten[v2]

However, in Mathematica you should really write vectors as simple lists, even if they will not display as columns.

POSTED BY: Gianluca Gorni
Posted 9 years ago
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