<s>[INST] Methods to solve a system of many Ax=B equations using least-squares I am working with a force measurement instrument which needs calibration via a calibration matrix. For each of a set of controlled measurements I have a vector $k$ of three known, independent values, and a corresponding vector $m$ containing three measured values, that due to instrument constraints end up being non-orthogonal.
From each measurement, I can assemble an equation in the form
$Cm = k$
where $C$ is a 3x3 calibration matrix for that measurement, found by solving the system.
My goal is to find some calibration matrix that is the least-squares best fit for ALL the measurements in the set of measurements. That would mean I would have a system like:
$Cm_1 = k_1\\
Cm_2 = k_2\\
...\\
Cm_n = k_n$
that I would have to solve for C, and that is my question: how do I solve such a system, where I have a MATRIX as the unknown?
I am not familiar with heavy math notation, and I plan to solve this using Python (Numpy/Scipy), so I'm looking more for a theoretical basis and proper nomenclature of which kind of procedure I should use, and then I could figure out how to implement it numerically.
Any help is much appreciated, thanks for reading!
 [/INST] Let's denote $C$ as 
\[ C = \begin{pmatrix} c_{11} & c_{12} & c_{13}\\ c_{21} & c_{22} & c_{23} \\ c_{31} & c_{32} & c_{33} \end{pmatrix} \]
We can write the equation $Cm_i = k_i$ as 
\begin{align*}
  m_{i1} c_{11} + m_{i2}c_{12} + m_{i3} c_{13} &= k_{i1}\\
  m_{i1} c_{21} + m_{i2}c_{22} + m_{i3} c_{23} &= k_{i2}\\  
  m_{i1} c_{31} + m_{i2}c_{32} + m_{i3} c_{33} &= k_{i3}
\end{align*}
or 
$$
 \begin{pmatrix} m_{i1} & m_{i2} & m_{i3} & 0 & 0 &0 & 0 & 0 &0\\
0 & 0 & 0 & m_{i1} & m_{i2} & m_{i3} & 0 & 0 & 0\\
 0 & 0 &0 & 0 & 0 &0 & m_{i1} & m_{i2} & m_{i3}\end{pmatrix}
\begin{pmatrix} c_{11} \\ c_{12}\\c_{13}\\ c_{21} \\ c_{22} \\ c_{23} \\ c_{31} \\ c_{32} \\c_{33} \end{pmatrix} = \begin{pmatrix} k_{i1} \\ k_{i2} \\ k_{i3}\end{pmatrix}
$$
Doing this for all $i$ gives 
$$
 \begin{pmatrix} m_{11} & m_{12} & m_{13} & 0 & 0 &0 & 0 & 0 &0\\
0 & 0 & 0 & m_{11} & m_{12} & m_{13} & 0 & 0 & 0\\
 0 & 0 &0 & 0 & 0 &0 & m_{11} & m_{12} & m_{13}\\
& \vdots & &&&&& \vdots \\
m_{n1} & m_{n2} & m_{n3} & 0 & 0 &0 & 0 & 0 &0\\
0 & 0 & 0 & m_{n1} & m_{n2} & m_{n3} & 0 & 0 & 0\\
 0 & 0 &0 & 0 & 0 &0 & m_{n1} & m_{n2} & m_{n3}\end{pmatrix}
\begin{pmatrix} c_{11} \\ c_{12}\\c_{13}\\ c_{21} \\ c_{22} \\ c_{23} \\ c_{31} \\ c_{32} \\c_{33} \end{pmatrix} = \begin{pmatrix} k_{11} \\ k_{12} \\ k_{13} \\ \vdots \\ k_{n1} \\ k_{n2} \\ k_{n3}\end{pmatrix}
$$
Now apply your usual least squares method.
</s>