Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning: "Parethesize the multiplication of 'D' and its transpose to ensure the result is Hermetian."

enter image description here

As you see in the screen shot above, I have the following expression in my Matlab m-file code:
K = P * D * D' * P;
Where, P is an nxn matrix, and D is a nx1 column vector (n=4, if it matters).

Why am I getting this warning message?
What changes if I use or don't use parenthesis there?

like image 858
hkBattousai Avatar asked May 23 '12 16:05

hkBattousai


2 Answers

Floating-point arithmetic is not associative. So in general, a * (b * c) won't necessarily give the same result as (a * b) * c.

Your statement as written is equivalent to ((P * D) * D') * P, so the compiler is warning you that if you're relying on the Hermitian symmetry of D * D', you should force it to calculate exactly that.

like image 71
Oliver Charlesworth Avatar answered Sep 21 '22 00:09

Oliver Charlesworth


As a side note: you can always do

K = (K + K') / 2;

To enforce the Hermetian-ity of K, but it's better to compute it as Hermitian in the first place as is suggested by the P * (D * D') * P hint.

Edit: Actually, one thing to note is that K is only going to be necessarily Hermitian if P is diagonal in general. Even with P as a permutation matrix (as the letter implies), there's not guarantee of K being Hermitian. The only guaranteed Hermitian part D * D'.

like image 42
Chris A. Avatar answered Sep 21 '22 00:09

Chris A.