Given a $k$-order polynomial in two variable $p(x, y)$ defined on a polygon domain $K$. And I want to numerically expand it to the following form
$$ p(x, y) = c_0 + c_1 x + c_2 y + c_3 x^2 + c_4 xy + c_5 y^2 + .... $$
Let $\{\phi_i\}_{i=0}^{n_k-1}$ are all the basis with form $x^my^n$, here $m, n$ are non-negative integers and
$$ \begin{aligned} m + n &\leq k,\\ n_k &= \frac{(k+1)(k+2)}{2} \end{aligned} $$
I have tried to do it by $L^2$ projection, namely, solve the following linear equation
$$ \begin{bmatrix} (\phi_0, \phi_0)_K & (\phi_0, \phi_1)_K & \cdots & (\phi_0, \phi_{n_k-1})_K \\ (\phi_1, \phi_0)_K & (\phi_1, \phi_1)_K & \cdots & (\phi_1, \phi_{n_k-1})_K \\ \vdots & \vdots & \ddots & \vdots \\ (\phi_{n_k-1}, \phi_0)_K & (\phi_{n_k-1}, \phi_1)_K & \cdots & (\phi_{n_k-1}, \phi_{n_k-1})_K \\ \end{bmatrix} \begin{bmatrix} c_0 \\ c_1 \\ \vdots \\ c_{n_k-1} \end{bmatrix} = \begin{bmatrix} (p(x, y), \phi_0)_K \\ (p(x, y), \phi_1)_K \\ \vdots \\ (p(x, y), \phi_{n_k-1})_K \end{bmatrix} $$ where $(\phi_i, \phi_j)_K = \int_K\phi_i\phi_j\mathrm d x\mathrm d y$
But when the area of domain $K$ is very small, or the degree $k$ is bigger, the left matrix is nearly singular, then this system can not be solved robustly.
Any suggestions?