Generaly:
Given a set of n data points x1...xn, y1...yn, with corresponding z1...zn and degree p, find a polynomial of degree p that fits the data with a minimal error in the least squares sense.
In my case, I need to find a polynomial of 3rd and 4th degree. I've started to do it just like in the article: Interpolation of 3D Surfaces for Contact Modeling page 10-11, formulas (2.7 - 2.9).
But I'm stack on the formula (2.7) and my question is: what will be the correct representation of this formula in reference to 3rd and 4th degree? My first idea (for 3rd degree) was:
$z = a_1 + a_2x + a_3y + a_4xy + a_5x^2y + a_6xy^2 + a_7x^2y^2 + a_8x^3y^2 + a_9x^2y^3 + a_{10} x^3y^3 $
But it doesn't fit with with general formula (2.7), where at the end is:
$ ... +a_{(2p+2)}x^py^p $
So, for $ p = 3 $ it should ended with $ ... + a_8x^3y^3 $,
and for $ p = 4 $ it should be ended with $ ... + a_{10}x^4y^4 $
In my further work I will be using a Vandermonde Matrix to calculate it in my own application, so Matlab solutions is not helpful here.
Okay, for those it may concern - the resolution of my question is:
When $ p = 3 $, the matrix for i-th row is:
$$ \begin{matrix} 1 & x_i & y_i & x_{i}^2 & x_iy_i & y_{i}^2 & x_{i}^3 & x_{i}^2y_i & x_iy_i^2 & y_i^3 \\ \end{matrix} $$
the formula is:
$ z=a_1+a_2x+a_3y+a_4x^2+a_5xy+a_6y^2+a_7x^3+a_8x^2y+a_9xy^2+a_{10}y^3 $
And for $ p = 4 $, the matrix for i-th row is:
$$ \begin{matrix} 1 & x_i & y_i & x_{i}^2 & x_iy_i & y_{i}^2 & x_{i}^3 & x_{i}^2y_i & x_iy_i^2 & y_i^3 & x_i^4 & x_i^3y_i & x_iy_i^3 & y_i^4 \\ \end{matrix} $$
the formula is:
$ z=a_1+a_2x+a_3y+a_4x^2+a_5xy+a_6y^2+a_7x^3+a_8x^2y+a_9xy^2+a_{10}y^3+a_{11}x^4+a_{12}x^3y+a_{13}x^2y^2+a_{14}xy^3+a_{15}y^4 $
I hope that this will be helpful for somebody in the future.