element-wise exponential of matrix returns all 1s

20 次查看(过去 30 天)
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.

回答(2 个)

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

James Tursa
James Tursa 2020-3-30
编辑:James Tursa 2020-3-30
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.

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by