I have some samples of data of the form $x,y$ and $z=f(x,y)$. I wish to fit a plane (i.e. $z = Ax + By + C$) to the data with the smallest mean square errors. I have found an "answer" in section 3 of this document, and several other locations too but the answers always end with variations of "now solve these equations and you can find $A$, $B$ and $C$"
I just about have the ability to solve these equations, but the process gets so messy that the likelihood of me making a mistake is quite high (and I need a guaranteed-correct answer). Surely someone has written out the full solution longhand somewhere - i.e. in the form $A=\dots$, $B=\dots$ and $C=\dots$ anyone know where this has been done?
EDIT: I see two answers already which leave out the last step as being trivial... and indeed they don't require any advanced maths... but you do need quite a big whiteboard to work it all out and the scope for making a mistake along the way is quite large. Indeed I noticed that assorted tutorials going through worked examples always have rather neat whole numbers. I find it hard to believe that there is nowhere online where someone has worked out the general case. I.e. find $A$, $B$ and $C$ in the following set of equations...
$$Ad+Be+Cf=g$$
$$Ah+Bi+Cj=j$$
$$Al+Bm+Cn=p$$
...where $d$ to $p$ are all constants.
If you don't feel confident with the resolution of a $3\times3$ system, work as follows:
$$\bar z=A\bar x+B\bar y+C$$
$$z_i-\bar z=A(x_i-\bar x)+B(y_i-\bar y)$$ or $$\hat z_i=A\hat x_i+B\hat y_i.$$
$$\sum \hat z_i\hat x_i=A\sum \hat x_i^2+B\sum \hat x_i\hat y_i\\ \sum \hat z_i\hat y_i=A\sum \hat x_i\hat y_i+B\sum \hat y_i^2$$
which is $2\times 2$. This gives you $A$ and $B$.
By Cramer, $$A=\frac{\sum \hat z_i\hat x_i\sum \hat y_i^2-\sum \hat z_i\hat y_i\sum \hat x_i\hat y_i}{\sum \hat x_i^2\sum \hat y_i^2-\left(\sum \hat x_i\hat y_i\right)^2}\\ B=\frac{\sum \hat x_i^2\sum \hat z_i\hat x_i-\sum\hat z_i\hat x_i\sum \hat x_i\hat y_i}{\sum \hat x_i^2\sum \hat y_i^2-\left(\sum \hat x_i\hat y_i\right)^2}$$
$$C=\bar z-A\bar x-B\bar y.$$
For convenient evaluation of the sums, notice that
$$\sum \hat u_i\hat v_i=\sum u_iv_i-N\bar u\bar v,$$ i.e. $$\overline{\hat u\hat v}=\overline{uv}-\bar u\bar v.$$ Then
$$\begin{align}A&=\frac{(\overline{zx}-\bar z\bar x)(\overline{y^2}-\bar y^2)-(\overline{zy}-\bar z\bar y)(\overline{xy}-\bar x\bar y)}{(\overline{x^2}-\bar x^2)(\overline{y^2}-\bar y^2)-(\overline{xy}-\bar x\bar y)^2}\\ B&=\frac{(\overline{x^2}-\bar x^2)(\overline{zy}-\bar z\bar y)-(\overline{zx}-\bar z\bar x)(\overline{xy}-\bar x\bar y)}{(\overline{x^2}-\bar x^2)(\overline{y^2}-\bar y^2)-(\overline{xy}-\bar x\bar y)^2}\\ C&=\bar z-A\bar x-B\bar y.\end{align}$$