# Product of elementary row equivalent operation matrix formula

Trying to figure something general regarding row equivalent matrices.

Say I Have $$A, B$$ two matrices of some size $$m \times n$$. I know that $$A, B$$ are row equivalent and their rows are linearly independent. (e.g., $$A, B$$ rows are both a different span base for the same subspace).

So finally, there is a matrix $$P$$, invertible, such that $$A = PB$$.

Would like to determine a formula for $$P$$.

Seems that $$P$$ rows are: the coordinates of $$B$$ rows regarding $$A$$ base.

Is it correct?

How can this be proven?

Will this work if $$A, B$$ rows are not linearly independent?

Seems that $$P$$ rows are: the coordinates of $$B$$ rows regarding $$A$$ base.

Close: it's the other way around. That is, the rows of $$P$$ are the coordinates of $$A$$ with respect to the basis formed by the rows of $$B$$.

The first thing to note is that $$\begin{bmatrix} x_1 & x_2 & \ldots & x_n\end{bmatrix}\begin{bmatrix}v_1 \\ \hline v_2 \\ \hline \vdots \\ \hline v_n \end{bmatrix} = [x_1 v_1 + x_2 v_2 + \ldots + x_nv_n],$$ where $$x_1, \ldots x_n$$ are scalars and $$v_1, \ldots, v_n$$ are row vectors of the same dimension. That is, multiplying on the left by a row vector simply produces a linear combination of the rows, where the coefficients are just the entries in the row vector. Further, $$\begin{bmatrix}u_1 \\ \hline u_2 \\ \hline \vdots \\ \hline u_n \end{bmatrix}B = \begin{bmatrix}u_1B \\ \hline u_2B \\ \hline \vdots \\ \hline u_nB \end{bmatrix}.$$ That is, multiplying two matrices together is equivalent to multiplying each individual row of the first matrix to the second, and placing the resulting row vectors as rows in a new matrix. Both of these facts can be verified by the definition of matrix multiplication.

So, we can interpret the rows of $$PB$$ as linear combinations of the rows of $$B$$. That is, the rows of the resulting matrix $$A$$ are coordinate row vectors in terms of the rows of $$B$$. That is, the rows of $$P$$ are the coordinates of the rows of $$A$$ with respect to the rows of $$B$$.

Would like to determine a formula for $$P$$.

If you multiply both sides of $$A = PB$$ by $$B^*$$ ($$B^\top$$ is fine in the real case), then $$B$$ having linearly independent rows implies $$BB^*$$ is invertible. So, you can simply take $$P = (B^*B)^{-1}A$$.

Will this work if $$A,B$$ rows are not linearly independent?

You can get a formula for $$P$$ using the Moore-Penrose pseudoinverse. If $$A = PB$$, then using the pseudoinverse property $$BB^+B = B$$, we have $$AB^+B = PBB^+B = PB = A.$$ I claim that $$Q = AB^+ + W(I - BB^+)$$ is a viable solution to $$P$$, for any square matrix $$W$$ of the appropriate size (yes, there are indeed multiple solutions). We then have $$QB = (AB^+ + W(I - BB^+))B = AB^+B + W(B - BB^+B) = AB^+B + 0 = A.$$ So, every value of $$Q$$ is a suitable choice for $$P$$. Note that, when $$B$$ has linearly independent rows, then $$BB^+ = I$$, so there will be only one solution generated, which must be the unique solution.