Solution (source code)

= Solution

Take the <inner product> linear in its first argument; for a real space no conjugation convention is needed. Insert $u^*=\sum_{j=1}^n a_j u_j$ into the orthogonality condition against each <basis> vector $u_i$. The <normal equations> are
$$
\boxed{\sum_{j=1}^n(u_j,u_i)a_j=(x,u_i),\qquad1\le i\le n.}
$$
Equivalently $Ha=b$, where $H_{ij}=(u_j,u_i)$ and $b_i=(x,u_i)$. This orientation of the <Gram matrix> matches the stated inner-product convention. It is Hermitian and positive definite: for a nonzero <coefficient> vector $a$,
$$
a^*Ha=\left\|\sum_j a_j u_j\right\|^2>0
$$
by <linear independence> of the <basis>. Hence $H$ is invertible and $a=H^{-1}b$ gives existence and uniqueness of $u^*$. For an <orthonormal basis> this simplifies to $a_i=(x,u_i)$; for a general <basis> the Gram inverse correctly accounts for interactions between <basis> vectors.