# How to solve xA=B matrix which I need x

For example, for matrix A, B, I know that when I use LinearSolve[A,B] that means it will solve for x which fulfill Ax=B.

However, what if xA=B case. I was trying to inverse A and B and make B^-1x=A^-1 but the A is not invertible so how I solve is..

Solve[{{x1 + x2 + x3, 5 x1 + 6 x2 + 11 x3}, {y1 + y2 + y3, 5 y1 + 6 y2 + 11 y3}} ==
{{1, 0}, {0, 1}}, {x1, x2, x3, y1, y2, y3}]


But it doesn't make sense and if matrix x is 5x5 or something like that, it would be very hard.

Can anyone tell me or suggest for a better way to solve this kind of problem? Thank you!

• Use Transpose, like LinearSolve[Transpose[A], Transpose[B]]? – Carl Woll Apr 22 '17 at 5:32
• Take the transpose of xA=B: A^T x^T = B^T and you have the form you want. – mjw Dec 5 '17 at 22:14

You did not give example of A and B

A0 = {{1, 1, 3}, {2, 0, 4}, {-1, 6, -1}};
B0 = {{2, 19, 8}};
x = Transpose@LinearSolve[Transpose[A0], Transpose[B0]]


Verify in Matlab:

>> A=[1 1 3;2 0 4;-1 6 -1];
>> B=[2 19 8];
>> x=B/A

x =

1.000000000000000   2.000000000000000   3.000000000000000


Why this works? Because B/A is the same as (A'\B')' and \ is Mathematica's LinearSolve

Another example

A0={{1,2,3},{4,5,8},{9,8,7}};
B0={{1,3,4},{5,6,7}};
x=Transpose@LinearSolve[Transpose[A0],Transpose[B0]]//N


Matlab:

>> A=[1 2 3;4 5 8;9 8 7];
>> B=[1 3 4;5 6 7];
>> x=B/A

x =

2.550000000000000  -0.500000000000000   0.050000000000000
1.400000000000000                   0   0.400000000000000

eqns = Thread /@
Thread[{{x1 + x2 + x3, 5 x1 + 6 x2 + 11 x3}, {y1 + y2 + y3,
5 y1 + 6 y2 + 11 y3}} == {{1, 0}, {0, 1}}] // Flatten

(*  {x1 + x2 + x3 == 1, 5 x1 + 6 x2 + 11 x3 == 0, y1 + y2 + y3 == 0,
5 y1 + 6 y2 + 11 y3 == 1}  *)

sol = Solve[eqns, {x1, x2, x3, y1, y2, y3}][[1]] //
Simplify // Quiet

(*  {x2 -> 1/5 (11 - 6 x1), x3 -> 1/5 (-6 + x1), y2 -> 1/5 (-1 - 6 y1),
y3 -> (1 + y1)/5}  *)


x1 and y1 are arbitrary

Verifying,

And @@ (eqns /. sol) // Simplify

(*  True  *)


For simplicity choose {x1 -> 0, y1 -> 0}

sol2 = {{x1 -> 0, y1 -> 0}, sol /. {x1 -> 0, y1 -> 0}} //
Flatten // SortBy[#, First] &

(*  {x1 -> 0, x2 -> 11/5, x3 -> -(6/5), y1 -> 0, y2 -> -(1/5), y3 -> 1/5}  *)

And @@ (eqns /. sol2)

(*  True  *)