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

大城市里の小女人 提交于 2019-12-10 15:39:49

问题


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?


回答1:


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.




回答2:


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'.



来源:https://stackoverflow.com/questions/10724549/warning-parethesize-the-multiplication-of-d-and-its-transpose-to-ensure-the

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!