MATLAB Answers

1

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

Asked by Oliver Woodford on 17 Jun 2015
Latest activity Edited by Stephen Cobeldick 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

>> 2./3
ans =
0.6667
>> 2.\3
ans =
1.5000
The documentation clearly states what each function does:
Stephen, what he is asking is something else namely
>> 2./3
ans =
0.6667
>> 3.\2
ans =
0.6667
so I think they will always give the same result
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.

2 Answers

Answer by James Tursa
on 17 Jun 2015
 Accepted Answer

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.

  0 Comments

Sign in to comment.


Answer by 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

I didn't ask about A.\B though

Sign in to comment.