8 views (last 30 days)
Show older comments
Randy A Lemons on 25 Jun 2019
Commented: Randy A Lemons on 25 Jun 2019
Accepted Answer: Matt J
Open in MATLAB Online
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 Comment Show -1 older commentsHide -1 older comments
Show -1 older commentsHide -1 older comments
John D'Errico on 25 Jun 2019
Direct link to this comment
https://support.mathworks.com/matlabcentral/answers/468709-any-way-to-speed-up-calculation-of-a-large-complex-exponential#comment_717893
Open in MATLAB Online
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.
Sign in to comment.
Sign in to answer this question.
Accepted Answer
Matt J on 25 Jun 2019
Edited: Matt J on 25 Jun 2019
Open in MATLAB Online
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 Comment Show -1 older commentsHide -1 older comments
Show -1 older commentsHide -1 older comments
Randy A Lemons on 25 Jun 2019
Direct link to this comment
https://support.mathworks.com/matlabcentral/answers/468709-any-way-to-speed-up-calculation-of-a-large-complex-exponential#comment_717902
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.
Sign in to comment.
More Answers (0)
Sign in to answer this question.
See Also
Categories
RadarPhased Array System ToolboxWaveform Design and Signal SynthesisMatched Filter and Ambiguity Function
Find more on Matched Filter and Ambiguity Function in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Contact your local office