## Test of rotation matrix multiplication ## Error in matrix multiplication ## There is some error with column-uncorrelated matrix multiplication. version ## Complex rotation matrix ## Generate a complex rotation matrix theta = randn * pi; cs = cos (theta) phase = sign (randn + i * randn); sn = sin (theta) * phase M = [cs, sn; -sn', cs] ## ## Check abs (cs) ^ 2 + abs (sn) ^ 2 == 1 ## ## Matrix products: M'*M, M*M' M' * M M * M' ## ## Element-wise products Mt = M'; M (1, :) * Mt M (2, :) * Mt Mt * M (:, 1) Mt * M (:, 2) [Mt(1, :) * M(:, 1), Mt(1, :) * M(:, 2); Mt(2, :) * M(:, 1), Mt(2, :) * M(:, 2)] ## Real rotaion matrix ## Generate a real rotation matrix theta = randn * pi; cs = cos (theta) phase = 1; sn = sin (theta) * phase M = [cs, sn; -sn', cs] ## ## Check abs (cs) ^ 2 + abs (sn) ^ 2 == 1 ## ## Matrix products: M'*M, M*M' M' * M M * M' ## ## Element-wise products Mt = M'; M (1, :) * Mt M (2, :) * Mt Mt * M (:, 1) Mt * M (:, 2) [Mt(1, :) * M(:, 1), Mt(1, :) * M(:, 2); Mt(2, :) * M(:, 1), Mt(2, :) * M(:, 2)] ## Note ## M' seems to have unwanted numerical error in octave! ## The element-wise product is good, but matrix product has some error ## where the entries should be zeros. ## If we try real rotation matrix, it shows same.