Equation with 2 unknowns I'm trying to calculate the coefficients of $2$ numbers. I know $2$ values and the answer of their equation. I tried doing an equation with $2$ unknowns, but when I try different equations with the values I have, the answer may vary, which I don't understand.
This are my values :

I thought the coefficient for $x$ was $0.5$ and $y$ was $0.45$ to get the answer, BUT if I try on another line it won't work. I am confused on what would be the equation with $X$ and $Y$ to get the answer?
 A: You want to write
$ z_i = a x_i + b y_i , \hspace{30pt} i = 1, 2, ..., 16 $
Let
$ Z = \begin{bmatrix} z_1 \\ z_2 \\ \vdots \\ z_{16} \end{bmatrix} $
and
$ X = \begin{bmatrix} x_1 && y_1 \\ x_2 && y_2 \\ \vdots && \vdots \\ x_{16} && y_{16} \end{bmatrix}$
Then, we want to write
$ Z = X u $
where $ u = \begin{bmatrix} a \\ b \end{bmatrix} $
The least-squares solution for $u$ is
$ u = (X^T X)^{-1} X^T Z $
Performing this calculation, will results in
$ u = \begin{bmatrix} 0.474090909 \\ 0.474090909 \end{bmatrix} $
These are the optimal value for the coefficients $a$ and $b$ in the least squares sense.  If you compute the errors, you'll find that the root mean squared error (RMSE) is $ \approx 0.1776 $
However, if you modify the model to include a constant, as @ClaudeLeibovici commented, i.e.
$ z_i = a + b x_i + c y_i \hspace{30pt} , i = 1, 2, \dots, 16 $
Then in this case, the matrix $X$ is modified to
$ X = \begin{bmatrix} 1 && x_1 && y_1 \\ 1 && x_2 && y_2 \\ \vdots && \vdots && \vdots \\ 1 && x_{16} && y_{16} \end{bmatrix} $
And
$ u = \begin{bmatrix} a \\ b \\ c \end{bmatrix} $
And after applying the formula, you get
$ u = \begin{bmatrix} -0.225 \\ 0.525 \\ 0.525 \end{bmatrix} $
Using these model values results in a root mean squared error (RMSE) of $ \approx 0.16413$
which is better than the previous model.
To make things even better, we can make the model as follows
$z_i = a + b x_i + c y_i + d x_i^2 + e x_i y_i + f y_i^2 $
which is a quadratic model.
In this case, matrix $X$ becomes
$ X = \begin{bmatrix} 1 && x_1 && y_1 && x_1^2 && x_1 y_1 && y_1^2 \\
1 && x_2 && y_2 && x_2^2 && x_2 y_2 && y_2^2\\
\vdots && \vdots && \vdots && \vdots && \vdots && \vdots \\
1 && x_{16} && y_{16} && x_{16}^2 && x_{16} y_{16} && y_{16}^2 \end{bmatrix} $
And
$ u = \begin{bmatrix} a \\ b \\ c \\ d \\ e \\ f \end{bmatrix} $
Using the same formula, one finds that
$ u = \begin{bmatrix} 0 \\ 0.475 \\ 0.475 \\ -0.05 \\ 0.116 \\ -0.05 \end{bmatrix}$
And the root mean squared error (RMSE) is $\approx 0.0302 $ which, as expected, is better than the previous models.
