Basically I have an overdetermined linear system of equations Ax=b, I can use numpy.linalg.lstsq to obtain the least square solution to this latter. However, when I multiply both sides of the equation by a weight diagonal matrix F, the least square solution is different while the equations are technically not. Here is a minimal example:
$A=\begin{bmatrix}1&2&3\\1&3&6\\1&6&2\\1&4&5\end{bmatrix}$ $b=\begin{bmatrix}1\\2\\3\\4\end{bmatrix}$ $F=\begin{bmatrix}0.1&0&0&0\\0&1&0&0\\0&0&10&0\\0&0&0&2\end{bmatrix}$
The solution given of numpy.linalg.lstsq to Ax=b is $x=\begin{bmatrix}-1.56643\\0.685315\\0.374126\end{bmatrix}$
The solution given of numpy.linalg.lstsq to FAx=Fb is $x=\begin{bmatrix}-21.46375975\\3.27144095\\2.41928963\end{bmatrix}$
I though about the equations having different weights in the least square, leading to a different solution chosen by the algorithm, but I am not sure if this is the correct reasoning.
The code:
from numpy import array, diag, dot
from numpy.linalg import lstsq
A = array([[1, 2, 3], [1, 3, 6], [1, 6, 2], [1, 4, 5]])
b = array([1, 2, 3, 4]).T
F = diag([0.1, 1, 10, 2])
print(lstsq(A, b, rcond=None)[0]) #[-1.56643357 0.68531469 0.37412587]
print(lstsq(dot(F,A), dot(F,b), rcond=None)[0]) #[-21.46375975 3.27144095 2.41928963]