Search code examples
matlabmatrixwarningsmultiplicationparentheses

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?


Solution

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