Is A./B different from B.\A?
Show older comments
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
Accepted Answer
More Answers (2)
Alberto
on 17 Jun 2015
0 votes
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
on 17 Jun 2015
H. Sh. G.
on 28 Sep 2021
0 votes
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 Comments
Stephen23
on 28 Sep 2021
"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 documentation explains what MRDIVIDE does:
H. Sh. G.
on 28 Sep 2021
Hi Stephen,
Thank you for the reference.
Yes, I know that b/A gives pinv(A)*b, but what if I change the places and divide A/b, where b is a row vector?
I checked and it does the same type of calculations; i.e. x = A/b is a solution to b*x = A.
Indeed, a pseudo inverse of the row vector is calculated by the operator.
However, x*b does not result in A, if x is the (a) solution to the equation above.
For example:
A = [1 1 3; 2 0 4; -1 6 -1];
b = [2 19 8];
The equation x*A = b can be solved by x = b/A =>
x = b/A
x = 1×3
1.0000 2.0000 3.0000
Now:
x = A / b
0.1049
0.0839
0.2424
which is equal to A * pinv(b). Note: we know that the solution may not be a unique one.
But:
x*b gives:
0.2098 1.9930 0.8392
0.1678 1.5944 0.6713
0.4848 4.6061 1.9394
Different from A.
Thanks in advance for further clarifcations,
Hamed.
"Yes, I know that b/A gives pinv(A)*b."
It's incorrect. In some cases b/A is A*pinv(b) (and not the opposite as you wrote)
B=rand(2,4);
A=rand(3,4);
A/B
A*pinv(B)
but when rank(b) < size(b,1) such formula is not correct
B=rand(4,2);
A=rand(3,2);
A/B
A*pinv(B)
Now to your question.
In case B = b is a row vector, let consider the system
% x*B = A;
x is column vector (since is a row vector). This system works row by row of x and A independenty. So consider a row equation
% x(i) * b = A(i,:).
So what you ask is which scalar x(i) that when multiplying with a vector (b) must be equal to another vector A(i,:). Such solution does not exist unless A(i,:) is proportional to b. In general MATLAB returns the least square solution:
% x(i) = dot(A(i,:),b) / dot(b,b)
Illustration test :
b=rand(1,4);
A=rand(3,4);
A/b
A1=A(1,:); x1=dot(A1,b)/dot(b,b)
A2=A(2,:); x2=dot(A2,b)/dot(b,b)
A3=A(3,:); x3=dot(A3,b)/dot(b,b)
% Or all together
x=A*b'/(b*b')
Note that for a row vector b, pinv(b) is b'/(b*b').
And x*B will not match A, unless all the rows of A are proportional to b (which is a strong coincidence in general).
H. Sh. G.
on 29 Sep 2021
Thanks Bruno,
This explains my question well.
Categories
Find more on Quaternion Math in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!