element-wise exponential of matrix returns all 1s

10 ビュー (過去 30 日間)
AlexK
AlexK 2020 年 3 月 30 日
編集済み: James Tursa 2020 年 3 月 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 Center および File ExchangeMatrix Indexing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by