I do not understand why this script {8/2<5*3+1>9} with logical operators gives NO (0)?
Afficher commentaires plus anciens

I do not understand why the answer is zero while the statement is apprarently correct. See below:
4<16>9
Isn't it correct? The answer should have been 1
Réponse acceptée
Plus de réponses (2)
Matlab evaluates the expression from left to right, If you start with numbers from left to right in your expression, it will first evaluate 8/2 which is 4. Then it compares the numbers on either side of inequality operator, which is again true,since 4 is less than (5*3+1) = 16.
After completing this step it returns a logical true or 1. Then it advances to compare the numbers on either side of > operator, is 1 > 9 ? No. So, it returns a logical 0 at the end.
1 commentaire
M Yasir Muneeb
le 10 Oct 2022
Catégories
En savoir plus sur Assumptions dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!