# Solving $Ax=b$ for A, given multiple pairs of vectors, $x$ and $b$

I have n pairs of $n\times 1$ vectors $x$ and $b$. How can I find an $n\times n$ matrix A which satisfies $Ax=b$ for all the n pairs of vectors $x$ and $b$? I am using matlab, is there a build in function? What if I have more then n pairs of vectors, is there a way to get a best fit $n\times n$ matrix?

Let me rephrase the question alittle: I can produce many measurements of pairs of vectors x and b with a computer program. I know there exist a matrix A such that Ax=b for all these pairs (From physical theory). But there is some uncertainty in x and b. So how can I find this matrix? How many pairs do I need? Also the elements of each vector x sum to 0.

If the (column) vectors $x_{1}, \dots, x_{n}$ are linearly independent, put them in a matrix $$X = \begin{bmatrix} x_{1} & \dots & x_{n} \end{bmatrix},$$ which will be then invertible. Do the same for the $b_{i}$ $$B = \begin{bmatrix} b_{1} & \dots & b_{n} \end{bmatrix},$$ so that you have $$A X = B,$$ and then $$A = B X^{-1}.$$

If the $x_{i}$ are not independent, the task may be impossible (for instance when $x_{1} = x_{2}$ but $b_{1} \ne b_{2}$), or the solution might not be unique.

• I have that the sum of the elements in x_i are zero. I couldnt invert it. Is there a way to get a best fit matrix for many pairs of vectors? Commented Mar 6, 2017 at 13:23
• May also need regularization or pseudoinverse if $X$ is not of high enough dimension. Commented Mar 6, 2017 at 13:32

Another way if you want more flexibility in solving for $A$ is to use the Kronecker product together with vectorization to express matrix multiplication:

$${\bf M_{R(X)}}vec({\bf A}) = vec({\bf B)}$$

where $\bf M_{R(X)}$ means "multiply from the Right by X"

This is more powerful in the sense that you can impose other demands on $\bf A$ as well, for example extra cost functions like $$\min \|{\bf T_1}\text{vec}({\bf A}) - {\bf T_2}\|$$

This becomes more powerful as you can express more things treating $\bf A$ as a vector than you would be able to do if it were a matrix.