Gram-Schmidt process - Division by zero (ERROR)

627 Views Asked by At

I'm working with full-rank lattice basis, and I need to compute the Gram-Schmidt norms and coefficients to measure its quality. But during the process I have a division by 0.

The division by zero is normal when the vectors are not linear dependent, which is not the case. Others said that I should throw it away and move to the next vector. But I need all the coefficients and norms to solve my next problem.

What should I do to compute all the coefficients and norms?

 B[]  = (Full-rank Basis)
 c[]  = (Gram-Schmidt Norms)
 mu[] = (Gram-Schmidt Coefficients)

 for(k=0; k < NUM_VECTORS; k=k+1) {

    if(k==1) c[0] = InnerProduct(B[0], B[0]);
    c[k] = InnerProduct(B[k], B[k]);

    for (j=0; j<k; j=j+1) {
        s = InnerProduct(B[k], B[j]);

        for(i=0; i<j; i++)
            s -= mu[j][i] * mu[k][i] * c[i];

        s = s / c[j]; //<--- PROBLEM IS HERE (DIVISION BY ZERO) c[j] is 0!!

        mu[k][j] = s;
        c[k] -= s * s * c[j];
    }
}

You can also see this question.