element-wise exponential of matrix returns all 1s

20 views (last 30 days)
I would like to exponentiate each element of a matrix of complex numbers. I know I am missing something basic about the operation of the exp function however I cannot figure out what it is.
A = pi / (500e-6);
x = repmat([-1, 0, 1],3,1);
y = repmat([1,0,-1]',1,3);
thetas = A * (x.^2 + y.^2);
exp(-1i * thetas)
However when I run this code the result is
1.0000 - 0.0000i 1.0000 - 0.0000i 1.0000 - 0.0000i
1.0000 - 0.0000i 1.0000 + 0.0000i 1.0000 - 0.0000i
1.0000 - 0.0000i 1.0000 - 0.0000i 1.0000 - 0.0000i
I know that this is not what I want since I can see that
thetas =
1.0e+04 *
1.2566 0.6283 1.2566
0.6283 0 0.6283
1.2566 0.6283 1.2566
and if I exponentiate one of these values I shouldnt get 1. For example:
>> exp(-1i * 1.0e+04 * 1.2566)
ans =
0.9321 + 0.3622i
Stanger still if I run:
A = 12566;
x = repmat([-1, 0, 1],3,1);
y = repmat([1,0,-1]',1,3);
thetas = A * (x.^2 + y.^2);
exp(-1i * thetas)
I get the values I would expect.

Answers (2)

Fangjun Jiang
Fangjun Jiang on 30 Mar 2020
It's a matter of display. Run this and show the result again.
format long

James Tursa
James Tursa on 30 Mar 2020
Edited: James Tursa on 30 Mar 2020
Your calculations are sensitive to the input numbers. E.g.,
>> format longg
>> thetas(1)
ans =
12566.3706143592
>> exp(1i*thetas(1))
ans =
1 - 1.28566658371025e-12i
>> exp(1i * 1.0e+04 * 1.2566)
ans =
0.932105007914798 - 0.362188147542344i
Truncating the input causes this difference.

Products

Community Treasure Hunt

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

Start Hunting!