Strange problem with fractional exponents

5 vues (au cours des 30 derniers jours)
Josh Shamir
Josh Shamir le 22 Oct 2016
Commenté : Josh Shamir le 23 Oct 2016
Dear all,
I’m getting a strange problem: if I compute 27^1/3 I get 9, but according to the rules of fractional exponents I should get 3. Instead, if I compute 27^(1/3), thus altering the MATLAB default operations priority, I get 3 (the correct value based on the rules of fractional exponents).
I would like to know why this happens in MATLAB. It is strange that applying the MATLAB default priority of operations would lead to produce wrong results.
Thank you in advance,
Josh

Réponse acceptée

Walter Roberson
Walter Roberson le 22 Oct 2016
^ has higher priority than / does, so in the case of 27^1/3 it is being interpreted as (27^1)/3 which is 9.
Look at https://www.mathworks.com/help/matlab/matlab_prog/operator-precedence.html and notice that matrix division / is only #5 but matrix power ^ is #2

Plus de réponses (0)

Catégories

En savoir plus sur Numerical Integration and Differential Equations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by