Any way to speed up calculation of a large complex exponential?
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Randy A Lemons
el 25 de Jun. de 2019
Comentada: Randy A Lemons
el 25 de Jun. de 2019
I am dealing with the repeated calculation of the exponential of a complex array filled with numbers on the order of 1.04*10^8. This is for use in a FFT based laser propagation code that I have been tasked with implementing. The issue is that I often have to deal with arrays that are 2^12 by 2^12 elements and this means that each iteration of the exponential ends up taking around a second. In my attempts to troubleshoot why this particular computation was taking so long I tried using real numbers and saw that it was significantly faster.
I was wondering if anyone knew why computing the exponential of a complex number is so much slower than the exponential of a real number? In case you want a code to try out what I mean, this should work (i'm running on 2019a but it should be pretty universal).
A = 10^8+4*10^6*rand(2^12);
tic
for ii = 1:10
exp( 1i * A );
end
toc/10
tic
for ii = 1:10
exp( A );
end
toc/10
Ideally I would like to find a way to speed up this calculation but I am not hopeful. If anything an explanation for why it takes so much longer on comple data than real data would be interesting.
1 comentario
John D'Errico
el 25 de Jun. de 2019
Do you have any idea how large A is, and what the value of exp(A) would be? if you were to be able to compute it? It should have roughly 30,000,000 decimal digits. It will overflow, so the answer will always overflow to inf. But the exponential of i*A will be a complex number, with magnitude 1.
A = 10^8;
exp(A)
ans =
Inf
exp(i*A)
ans =
-0.36339 + 0.93164i
As such, it will actuallly require a computation for the imaginary argument, instead of just trapping out with an overflow to inf in the code.
Respuesta aceptada
Matt J
el 25 de Jun. de 2019
Editada: Matt J
el 25 de Jun. de 2019
One reason exp(A) is signficantly faster is that it is always Inf for the values of A you are feeding in. There is no computation involved. Another reason is that
exp(1i*A) = cos(A)+1i*sin(A)
which therefore takes twice as much memory and computation to evaluate. To speed things up, either use the GPU or consider changing A to type single instead of double.
Más respuestas (0)
Ver también
Categorías
Más información sobre Matched Filter and Ambiguity Function en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!