Confusion related to matrix inverse

I have this confusion related to matrix inverse. Lets say I have this equation

$AX=B$,

Then is it $X=A^{-1}B$ or $X=BA^{-1}$.

When I say A/B is it $A^{-1}B$ or $BA^{-1}$.

-

Matrix multiplication is not in general commutative, so you have to pay attention to the order of the factors when you multiply. To solve the equation $AX=B$, you want to get rid of the $A$ by multiplying it by its inverse, so you have to multiply on the left: $A^{-1}(AX)=(A^{-1}A)X=IX=X$. As usual, you must do exactly the same thing to the other side of the equation, so you end up with $X=A^{-1}B$, not $X=BA^{-1}$.

You should not say $B/A$ at all: division of matrices is undefined, so that combination of symbols is meaningless.

-

You multiply by $A^{-1}$ to cancel the $A$. So, to cancel $A$ from $AX$, you need to multiply by $A^{-1}$ on the left side...

Your solution is basically the following:

$$AX=B \Rightarrow A^{-1}AX=A^{-1}B \Rightarrow X= A^{-1}B$$

Similarly, if you solve $XA=B$, to cancel $A$ you need to multiply to the right, thus in that case, $X=BA^{-1}$.

-
@All Actually I am confused how the matlab does the work. If I have matrix A of size 3x4 and matrix B of size \$x4, if I do A/B it gives me a resultant matrix of size 3x4. If I do B/A it gives me a resultant matrix of size 4x3. I am not sure what matlab does and what equation it solves behind? – user34790 Oct 11 '12 at 3:16
@All Actually I am confused how the matlab does the work. If I have matrix A of size 3x4 and matrix B of size 4x4, if I do A/B it gives me a resultant matrix of size 3x4. If I do B/A it gives me a resultant matrix of size 4x3. I am not sure what matlab does and what equation it solves behind? – user34790 Oct 11 '12 at 3:24

In Matlab, if your matrix is not square and you ask it to do division with it, it uses the least squares solution. That solution matrix will be of dimension of the transpose. So for example if your matrix is 4x3, dividing gives a 3x4 matrix.

-
Least squares between which two matrices. I mean the inverse doesn't exits for a non square matrix 4x3 in this case. So what does it actually do to generate this 3x4 matrix. Least squares means least squared of the difference. So what does it compare to calculate the least squares – user34790 Oct 11 '12 at 3:46
A 3x4 matrix might have a right inverse which is what the least squares would be when using the unique one (has same column span as A's row span). I am talking A/A in Matlab. I am not sure what Matlab would do in the 4x3 case, though it may just use the same matrix since it is conformable and has conformable span (see the four fundamental matrix spaces). – adam W Oct 11 '12 at 11:23