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

173 ビュー (過去 30 日間)
Oliver Woodford 2015 年 6 月 17 日

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 件のコメント表示非表示 2 件の古いコメント
Stephen 2015 年 6 月 17 日
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.

サインインしてコメントする。

### 採用された回答

James Tursa 2015 年 6 月 17 日
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.
##### 6 件のコメント表示非表示 5 件の古いコメント
James Tursa 2021 年 10 月 29 日
Yes, your expectations are correct. For the MATLAB toolbox quaternion class objects, the q./p and p.\q operations are implemented as expected by multiplying by the inverse, and since multiplication is non-commutative you get different results.
>> x = rand(1,4)-0.5; x = x/norm(x); q = quaternion(x);
>> x = rand(1,4)-0.5; x = x/norm(x); p = quaternion(x);
>> q
q =
quaternion
-0.62168 + 0.46748i + 0.58112j + 0.23933k
>> p
p =
quaternion
0.64169 + 0.60532i - 0.26832j + 0.38709k
>> q./p
ans =
quaternion
-0.17923 + 0.38713i + 0.24217j + 0.87141k
>> p.\q
ans =
quaternion
-0.17923 + 0.96545i + 0.17j - 0.082977k
>> q*conj(p)
ans =
quaternion
-0.17923 + 0.38713i + 0.24217j + 0.87141k
>> conj(p)*q
ans =
quaternion
-0.17923 + 0.96545i + 0.17j - 0.082977k
>> which quaternion
C:\Program Files\MATLAB\R2020a\toolbox\shared\rotations\rotationslib\@quaternion\quaternion.m % quaternion constructor
Note that the / and \ operators are not implemented for this class:
>> q/p
Error using /
Arguments must be numeric, char, or logical.
>> p\q
Error using \
Arguments must be numeric, char, or logical.

サインインしてコメントする。

### その他の回答 (2 件)

Alberto 2015 年 6 月 17 日
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 件のコメント表示非表示 なし
Oliver Woodford 2015 年 6 月 17 日

サインインしてコメントする。

H. Sh. G. 2021 年 9 月 28 日
Hi every body.
I wonder what kind of calculations the division of a matrix (X) by a row vector (y), i.e. X/y, does, where both have the same number of columns.
The result is a column vector of the same number of rows that X has.
Recall that X./y divides all elements of each column in X by the element of y in the same column, resulting in a matrix with the same size of X.
##### 4 件のコメント表示非表示 3 件の古いコメント
H. Sh. G. 2021 年 9 月 29 日
Thanks Bruno,
This explains my question well.

サインインしてコメントする。

### Community Treasure Hunt

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

Start Hunting!