public Cholesky(final double[][] a) {
    n = a.length;
    el = buildMatrix(a);
    
    int i,j,k;
    double sum;
    if (el[0].length != n) throw new IllegalArgumentException("need square matrix");
    for (i=0;i<n;i++) {
      for (j=i;j<n;j++) {
        for (sum=el[i][j],k=i-1;k>=0;k--) sum -= el[i][k]*el[j][k];
        if (i == j) {
          if (sum <= 0.0)
            throw new IllegalArgumentException("Cholesky failed");
          el[i][i]=sqrt(sum);
        } else el[j][i]=sum/el[i][i];
      }
    }
    for (i=0;i<n;i++) for (j=0;j<i;j++) el[j][i] = 0.;
  }