What is the correct result? - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: General Forum (/forum-4.html) +--- Thread: What is the correct result? (/thread-21474.html) |
RE: What is the correct result? - Matt Agajanian - 04-22-2024 03:46 AM (04-21-2024 09:49 PM)Steve Simpkin Wrote:(04-21-2024 07:43 PM)Matt Agajanian Wrote: Hi all. I see. That TI technote explains that they made a change. But why didn’t the technote make any explanation as to why they did this? So, why the changeover? RE: What is the correct result? - klesl - 04-22-2024 10:19 AM 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 RE: What is the correct result? - carey - 04-22-2024 05:07 PM (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.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). RE: What is the correct result? - Matt Agajanian - 04-22-2024 07:04 PM So, is this to say MatLab and Numpy are the final word on this conundrum? RE: What is the correct result? - carey - 04-22-2024 08:41 PM (04-22-2024 07:04 PM)Matt Agajanian Wrote: So, is this to say MatLab and Numpy are the final word on this conundrum?I don’t think there is a “conundrum”, nor a “final word.” Matlab and Numpy are very popular scientific and engineering tools (though there are others). While it might sound convenient to have an international standard for all operator precedences and implied multiplications, analogous to the international standard (S.I) for units, note that even for units, for which the case for standardization is even more compelling, there exist many fields and applications that don’t subscribe to the S.I. system (e.g., mass of diamonds in carets). In my opinion, we must learn to live with (and maybe even value, as in “vive la différence”) variety in matters such as operator precedence and implied multiplication as these conventions are created by people, while in understanding nature (e.g., in physics), simplicity is the desired goal. But when in doubt, use PEMDAS! :) RE: What is the correct result? - Matt Agajanian - 04-23-2024 12:38 AM (04-22-2024 08:41 PM)carey Wrote:(04-22-2024 07:04 PM)Matt Agajanian Wrote: So, is this to say MatLab and Numpy are the final word on this conundrum?I don’t think there is a “conundrum”, nor a “final word.” Matlab and Numpy are very popular scientific and engineering tools (though there are others). In addition, when in doubt, write the expression in a manner which it’s clearly written so as to prevent ambiguity. |