Created
February 15, 2018 19:06
-
-
Save waldyrious/fe2fb40b30e9c0e32ae948606d5e2ef3 to your computer and use it in GitHub Desktop.
Comparison of Matlab/Octave .^2 with multiplication by the complex conjugate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = rand(5); | |
b = rand(5); | |
c = a + 1i*b; | |
% ------------------------------------------------------------------------- | |
% POW | |
tic(); | |
c1 = real(c).^2 + imag(c).^2; | |
toc() | |
% ------------------------------------------------------------------------- | |
% MUL BY COMPLEX CONJ | |
tic(); | |
c2 = c .* conj(c); | |
toc() | |
% ------------------------------------------------------------------------- | |
% Observations: | |
% - the results match (c1 == c2) | |
% - time with .^2 is consistently faster than using the complex conjugate. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment