exp doesn't return the expected values

9 vues (au cours des 30 derniers jours)
Ahmed
Ahmed le 22 Juil 2022
Commenté : Steven Lord le 22 Juil 2022
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

Réponse acceptée

Star Strider
Star Strider le 22 Juil 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 commentaires
Star Strider
Star Strider le 22 Juil 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 le 22 Juil 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...

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by