0

Why does this function handle in Matlab g = @(x)(4*x^5-A)/5/x^4; correspond to g(x) = (4x^5-A)/5x^4 and not to (4x^5-A)/(5/x^4)?

NoDataDumpNoContribution
  • 10,591
  • 9
  • 64
  • 104
P2o3l
  • 3
  • 1

1 Answers1

2

What you are observing is the left associativity of the division operator. Maybe we should simplify the example first, no anonymous function, just the operators:

>> 5/5/5
ans =
    0.2000
>> (5/5)/5
ans =
    0.2000
>> 5/(5/5)
ans =
     5
>> 

There isn't really a logical reason behind, but all programming languages I know have math operators like / left associative. * is also left associative, but it usually does not matter. When it comes to order of operation, also consider the precedence.

Daniel
  • 36,610
  • 3
  • 36
  • 69