Any way to speed up calculation of a large complex exponential?

조회 수: 10 (최근 30일)
Randy A Lemons
Randy A Lemons 2019년 6월 25일
댓글: Randy A Lemons 2019년 6월 25일
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
John D'Errico
John D'Errico 2019년 6월 25일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2019년 6월 25일
편집: Matt J 2019년 6월 25일
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.
  댓글 수: 1
Randy A Lemons
Randy A Lemons 2019년 6월 25일
Well that really does nake quite a bit of sense. I never really took a look at the output of the calculation for the real numbers. I guess there is a catch for too large of numbers.
I knew that it would take twice the memory at the end of the day but was hoping there was a way to avoid the direct calculation using eulers formula. Or rather I was hoping there was something sneaky that could be done similar to an fft.
I guess if there was Mathworks probably would have implemented it.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Coder에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by