Post Reply 
What is the correct result?
04-22-2024, 05:07 PM (This post was last modified: 04-22-2024 06:07 PM by carey.)
Post: #63
RE: What is the correct result?
(04-22-2024 10:19 AM)klesl Wrote:  According to me there is no PEMDAS or PEJMDAS in Matlab, it is up to user, which method selects.
You need to add multiplication sign or parenthesis
6/2(1+2) - error
6/(2(1+2)) - error
6/2*(1+2)=9
6/(2*(1+2))=1
[Image: ME184ZR2_t.png]
Your examples support the conclusion that there’s no PEJMDAS (operator precedence AND implied multiplication) in Matlab but don’t appear to me to support the conclusion that there’s no PEMDAS (operator precedence WITHOUT implied multiplication).

Example 1 displaying Error in Matlab shows there’s no implied multiplication using parentheses so no PEJMDAS but still can be PEMDAS. Note that the “P” for parentheses in PEMDAS only refers to operator precedence (i.e., operate first within parentheses), not implied multiplication via parentheses.

Example 2, same as Example 1 that parentheses can’t be used to imply multiplication so again no PEJMDAS but still can be PEMDAS.

Note (parenthetically :), that Examples 1 & 2 show it’s not fully “up to the user” in Matlab as implied multiplication via parentheses triggers an error.

Example 3 shows parentheses used for grouping but not for implied multiplication so PEMDAS.

Example 4, same as Example 3, showing parentheses for grouping and not implied multiplication so again PEMDAS.

As mentioned in one of my previous posts, Matlab (and Python’s Numpy) are generally aligned with PEMDAS, but since both have a huge number of operators and their documentation list differences in some operator precedences, things are (unfortunately :) more complicated than just PEMDAS vs PEJMDAS. However one shouldn’t go (too :) wrong applying PEMDAS in Matlab or Numpy, at least for the basic arithmetic operations (but will go wrong applying PEJMDAS in Matlab as examples 1 & 2 show).
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
What is the correct result? - hp41cx - 03-17-2024, 03:03 PM
RE: What is the correct result? - SammysHP - 03-17-2024, 04:33 PM
RE: What is the correct result? - hp41cx - 03-17-2024, 05:37 PM
RE: What is the correct result? - KeithB - 03-18-2024, 02:04 PM
RE: What is the correct result? - vaklaff - 03-18-2024, 06:57 PM
RE: What is the correct result? - johnb - 03-18-2024, 11:49 PM
RE: What is the correct result? - carey - 03-19-2024, 12:29 AM
RE: What is the correct result? - johnb - 03-18-2024, 11:40 PM
RE: What is the correct result? - KeithB - 03-19-2024, 01:58 PM
RE: What is the correct result? - mfleming - 03-19-2024, 08:43 PM
RE: What is the correct result? - johnb - 03-19-2024, 09:32 PM
RE: What is the correct result? - carey - 03-19-2024, 05:45 PM
RE: What is the correct result? - johnb - 03-19-2024, 09:19 PM
RE: What is the correct result? - KeithB - 03-19-2024, 09:41 PM
RE: What is the correct result? - vaklaff - 03-20-2024, 10:31 AM
RE: What is the correct result? - carey - 03-20-2024, 12:28 PM
RE: What is the correct result? - johnb - 03-20-2024, 03:50 PM
RE: What is the correct result? - mfleming - 03-20-2024, 09:21 PM
RE: What is the correct result? - DGM - 03-21-2024, 04:44 AM
RE: What is the correct result? - Jlouis - 03-21-2024, 07:04 PM
RE: What is the correct result? - carey - 03-21-2024, 09:19 PM
RE: What is the correct result? - carey - 03-21-2024, 08:24 PM
RE: What is the correct result? - mfleming - 03-21-2024, 08:58 PM
RE: What is the correct result? - johnb - 03-22-2024, 04:18 PM
RE: What is the correct result? - carey - 04-13-2024, 01:26 AM
RE: What is the correct result? - KeithB - 04-15-2024, 04:31 PM
RE: What is the correct result? - dm319 - 04-15-2024, 04:44 PM
RE: What is the correct result? - dm319 - 04-16-2024, 02:26 PM
RE: What is the correct result? - vaklaff - 04-17-2024, 04:23 PM
RE: What is the correct result? - dm319 - 04-18-2024, 12:33 PM
RE: What is the correct result? - dm319 - 04-16-2024, 02:05 PM
RE: What is the correct result? - carey - 04-22-2024, 12:50 AM
RE: What is the correct result? - klesl - 04-22-2024, 10:19 AM
RE: What is the correct result? - carey - 04-22-2024 05:07 PM
RE: What is the correct result? - carey - 04-22-2024, 08:41 PM



User(s) browsing this thread: 1 Guest(s)