MATLAB Answers

Is A./B different from B.\A?

184 views (last 30 days)
Oliver Woodford
Oliver Woodford on 17 Jun 2015
Edited: Stephen on 17 Jun 2015
Given two matrices, A and B, will A./B ever give a different answer from B.\A, or are these two expressions equivalent?
It seems that even for complex numbers they return the same thing. E.g.
>> A = sqrt(randn(3));
>> B = sqrt(randn(3));
>> isequal(A./B, B.\A)
ans = 1
  3 Comments
Stephen
Stephen on 17 Jun 2015
According to the documentation A.\B and B./A are the same:
  • ldivide: " B.\A divides each element of A by the corresponding element of B"
  • rdivide: " A./B divides each element of A by the corresponding element of B"
Unless the definition of "divide" is different, then these should be the same.

Sign in to comment.

Accepted Answer

James Tursa
James Tursa on 17 Jun 2015
I can't think of any reason why one would ever get different results for numeric types. I suppose there might be speed differences if one form used multi-threading and the other form didn't, but in tests I just ran they both appeared to take about the same amount of time.
User defined classes could of course overload them differently.

More Answers (1)

Alberto
Alberto on 17 Jun 2015
Both are pointwise, but A./B divides every element in A by the same element in B. A.\B divides every element in B by the same element in A.
  1 Comment
Oliver Woodford
Oliver Woodford on 17 Jun 2015
I didn't ask about A.\B though

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!