exp doesn't return the expected values

8 views (last 30 days)
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

Accepted Answer

Star Strider
Star Strider on 22 Jul 2022
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 Comments
Star Strider
Star Strider on 22 Jul 2022
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 on 22 Jul 2022
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...

Sign in to comment.

More Answers (0)

Tags

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!