exp doesn't return the expected values

I have a matrix which is defined like this
x = [1 2 3; 4 5 6; 7 8 9];
y = exp(x)
y = 3×3
1.0e+03 * 0.0027 0.0074 0.0201 0.0546 0.1484 0.4034 1.0966 2.9810 8.1031
Why am I getting this result ? I expected a matrix which contains element by element exp

 採用された回答

Star Strider
Star Strider 2022 年 7 月 22 日

0 投票

That is esactly what it is doing —
format longG
x = [1 2 3; 4 5 6; 7 8 9];
y = exp(x)
y = 3×3
1.0e+00 * 2.71828182845905 7.38905609893065 20.0855369231877 54.5981500331442 148.413159102577 403.428793492735 1096.63315842846 2980.95798704173 8103.08392757538
y11 = exp(1)
y11 =
2.71828182845905
y33 = exp(9)
y33 =
8103.08392757538
What were you expecting?
.

3 件のコメント

Ahmed
Ahmed 2022 年 7 月 22 日
Oh okay I am sorry, I just didn't notice that the format is different.
Star Strider
Star Strider 2022 年 7 月 22 日
No worries!
The ‘1.0e+3’ in the upper left of the display indicates that the entire displayed matrix is multiplied by the inverse of that number, ‘1E-3’ in this instance.
See the documentation on format for examples.
.
Steven Lord
Steven Lord 2022 年 7 月 22 日
I'm guessing they missed the factor of 1.0e+03 in the upper-left corner of the matrix and so thought MATLAB was returning 0.0027 for exp(1) when they expected 2.71828...

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

製品

リリース

R2021a

タグ

質問済み:

2022 年 7 月 22 日

コメント済み:

2022 年 7 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by