I am solving the following problem:
For given position vectors $\vec{x}_1,...,\vec{x}_n$ and $\vec{y}_1,...,\vec{y}_n$ we have following equations
$Q\vec{x}_i+\vec{b}=\vec{y}_i$, $i=1,...,n$
$Q^TQ=I$
with unknowns
$ Q= \begin{bmatrix} q_{11} & q_{12} & ... &q_{1k}\\ q_{21} & q_{22} & ... &q_{2k}\\ ... & ... & ... & ...\\ q_{k1} & q_{k2} & ... &q_{kk} \end{bmatrix} $ and $b=\begin{bmatrix} b_{1}\\ b_{2}\\ ...\\ b_{k} \end{bmatrix}$
(This is a system of $kn+k^2$ equations for $k^2+k$ unknowns, where $k=\dim\mathbb{R}^k$.) The problem is that $k^2$ equations from $Q^TQ=I$ are not linear. The naive solution: We ignore equality $Q^TQ=I$ and are left with $kn$ equations for $k^2+k$ unknowns:
$Q\vec{x}_i+\vec{b}=\vec{y}_i$, $i=1,...,n$
We assume that $n\geq 2k$ so that we get an overdetermined system of linear equations.
Task: Write down the matrix of this system and find the solution of the system, matrix $Q'$ and vector $b$ by least squares method. Because $Q'$ is not necessarily orthogonal, we correct it by taking $Q$ from QR decomposition $Q'=QR$. The solution to the problem are now matrix $Q$ and vector $b$
My solving:
$Q\vec{x}_i+\vec{b}=\vec{y}_i$ is equal to $\vec{x}_{i}^TQ^T + \vec{b}^T=\vec{y}_i^T$
For $n=3$ the system of equations looks like
$ \begin{bmatrix} \vec{x}_{1}^TQ^T + \vec{b}^T\\ \vec{x}_{2}^TQ^T + \vec{b}^T\\ \vec{x}_{3}^TQ^T + \vec{b}^T\\ \end{bmatrix} = \begin{bmatrix} \vec{y}_{1}^T\\ \vec{y}_{2}^T\\ \vec{y}_{3}^T\\ \end{bmatrix} $
to put in in the form $Ax=b$
$ \begin{bmatrix} \vec{x}_{1}^T& 1\\ \vec{x}_{2}^T& 1\\ \vec{x}_{3}^T& 1 \end{bmatrix} \cdot \begin{bmatrix} Q^T\\ \vec{b}^T \end{bmatrix} = \begin{bmatrix} \vec{y}_{1}^T\\ \vec{y}_{2}^T\\ \vec{y}_{3}^T \end{bmatrix} $
And then got $x=\begin{bmatrix} Q^T\\ \vec{b}^T \end{bmatrix} $ by solving $A^TAx=A^Tb$
and from there got $b$ from the last row and $Q'$ from the other rows.
For $Q'\vec{x}_i+b=\vec{y}_i$ i get corrent solutions. But after getting corrected $Q$ from QR decomposition, i get wrong solutions from this equation when swapping $Q'$ with $Q$.
How am i supposed to represent the system of equations differently