help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Octave and Please Excuse My Dear Aunt Sally


From: Schirmacher, Rolf
Subject: RE: Octave and Please Excuse My Dear Aunt Sally
Date: Fri, 27 May 2011 21:27:25 +0200

Hello,

> -----Original Message-----
> From: address@hidden
> [mailto:address@hidden Behalf Of clustro
> Sent: Friday, May 27, 2011 8:05 PM
> To: address@hidden
> Subject: Octave and Please Excuse My Dear Aunt Sally
> 
> 
> Hello everyone,
> 
> I tried doing this operation as a test:
> 
> 3*4/2*2
> 
> Following PEMDAS (Please Excuse My Dear Aunt Sally), I should get:
> 
> 3*4 = 12
> 

This is (3*4) ...

> 2*2 = 4
> 

This is (2*2) ...

> 12/4 = 3
> 

So, this now is (3*4) / (2*2)  (watch out for the parantheses)

> But instead, I get 12, because apparently octave is doing 4/2 
> first, and
> then multiplication.
> 

No, Octave is doing 3 * 4 * (1/2) * 2 (as expected due to PEMDAS) and you 
intend it to do 3 * 4 * (1/ (2*2)), which is clearly different due to the extra 
parantheses. 

> What on earth is octave doing? Apparently, I am not the only 
> person who
> thought Octave used PEMDAS (http://tinyurl.com/3rfsk9g, last 
> page). What
> order of operations is octave using?
> 
> This might seem like such a slight matter but there is a 
> bunch of code I
> have to go back and fix now because of this, and I just want 
> to make sure I
> know the correct priority of the operations to save myself 
> having to do it
> all over again.
> 
> Thanks,
> 
> -Brad Ridder
> 

Operator precedence is discussed in the manual. But, as you see, your Aunt is 
sufficient here ;-)

Regards,

Rolf



reply via email to

[Prev in Thread] Current Thread [Next in Thread]