I have a code from someone that I dont understand: This code is written in matlab and the function is to estimate linear geometric transformation [1] of a matrix using pinv. The size of first matrix is Nx3 which is the same as target matrix. The goal is to find geometric transformation matrix which can be initialized by affine to translate the first matrix to the target matrix. In this code before using least square, the ones column added to the first matrix which i dont understand mathematically, anybody can help me?
this is the code
% O is the source matrix
% Y is the target matrix
% Solve Y=X*B
%
% Inputs: (each row is a datapoint)
% O: Regressor (X=[ones(N,1) O], N num of rows)
% Y: Regressand
N = size(O,1);
X=[ones(N,1) O]; %%%% I dont understand here
B=pinv(X)*Y;
The B is the geometric transformation which is 4x3 and will send to the affine transformation in next step. Therefore, affine is initialized by B matrix. Appreciate if anybody can help me in this case.
The ones column added to $X$ is to account for the constant. For example, if you are trying to fit the model
$$ y(t) = ax_{1}(t)+bx_{2}(t)+cx_{3}(t)+d, $$
where the unknowns are $a$, $b$, $c$, $d$. Then you can write this in matrix form as
$$ y(t) = \begin{bmatrix}1,x_{1}(t),x_{2}(t),x_{3}(t)\end{bmatrix}\begin{bmatrix}d\\ a\\ b\\ c\end{bmatrix} $$
Stack a lot of these and you end up with your regressor and regressand.