[Math] Finding the matrix that transforms a given input vector into a given output vector

linear algebramatricessystems of equationsvectors

I have two vectors – the input and output. I would like to find a matrix that multiplied by the input vector gives the output vector.

What algorithms should be used? What is their complexity?

Best Answer

So you want a matrix, which given the input vector $a$ produces the output vector $b$.

Here is a rank-1 matrix which does that $$M=\frac{ba^T}{a^Ta}=ba^+$$ where $a^+$ is the pseudoinverse of $a$.


Later, you discover that you actually need to map a set of input vectors $\{a_k\}$ to a set of output vectors $\{b_k\}.\,\,\,$ Here is a matrix which addresses that situation $$M=BA^+$$ where $B$ is a matrix whose columns are the $\{b_k\}$ vectors, and ditto for $A$.


For a more complete solution, you can include contributions from the nullspace of $A$ $$M=BA^+ + G\,(I-AA^+)$$ where $G$ is an arbitrary matrix.

This solution remains valid when $A$ reverts to being the vector $a$, and is likely the answer to your original question.

Related Question