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

 Respuesta aceptada

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 comentarios

Ahmed
Ahmed el 22 de Jul. de 2022
Oh okay I am sorry, I just didn't notice that the format is different.
Star Strider
Star Strider el 22 de Jul. de 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 el 22 de Jul. de 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...

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Versión

R2021a

Etiquetas

Preguntada:

el 22 de Jul. de 2022

Comentada:

el 22 de Jul. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by