I have a set of functions $\{f_1,\ldots,f_n\}$ with an associated inner product
$\langle f_j,f_k\rangle=\int d^2z f_1^*f_2$ .
The functions are not linearly dependent; i.e. the rank $r<n$, where $r$ is unknown. I need to find the rank and an orthogonal basis for the space spanned by the functions, i.e. a set $\{g_1,\ldots,g_r\}$ where $\langle g_j,g_k\rangle=c_j\delta_{jk}$ and $c_j$ is an unimportant constant; that is it doesn't matter of the set is normalised.
What I've been doing so far is: find the overlap matrix $M_{ij}=\langle f_i,f_j\rangle$, compute the singular values, and count the nonzero singular values to get the rank. I then do a Gram-Schmidt with $r$ functions chosen from the initial $n$ in such a way as to minimise their inter-overlap (i.e. of the $n(n-1)/2$ overlaps I find the highest one and remove one of the corresponding states; this is iterated until I'm left with $r$ states on which to perform the Gram-Schmidt).
This usually works, but sometimes the selection procedure described above does not give $r$ independent functions and I'm unable to do the Gram-Schmidt.
As another option I was thinking I can use the singular vectors created in the singular value decomposition (I assume it doesn't matter if I choose the left- or right singular vectors). I couldn't find this written anywhere but it is my understanding that if there are $r$ nonzero singular values the corresponding $r$ singular vectors form an orthogonal basis for the desired space. Since the matrix I'm decomposing is the overlap matrix between my functions I take the singular vectors to be composed of coefficients multiplying my initial functions.
This however doesn't produce orthogonal vectors with respect to the inner product $\langle f_a, f_b\rangle$. So I'm thinking either I'm doing something wrong, or the singular vectors are orthogonal but with respect to the regular cartesian product of the actual vectors, and not as coefficients of the initial functions leading to orthogonal functions with the above inner product.
Does this method make sense? And if not is there another way to find the maximal set of orthogonal functions?