I am using a mathematical function to estimate the covariance matrix for some process from the variances and then using this covariance matrix in a [generalised least squares](https://en.wikipedia.org/wiki/Generalized_least_squares) estimation of the slope and intercept of the data. 

However, sometimes I get nonsense values (i.e. 10e123, when the slope should be ~1) for the slope. Adding a small amount of Gaussian noise to the variances when this happens seems to remove the problem, but it is a bit inelegant of a solution. I have checked and there is no noticeable difference between the covariance matrix condition number/determinant/condition number when I get the erroneous result and not. 

I was wondering if anyone knows how I either (1) detect when I will get an erroneous result so that I can add the noise before the slope is calculated or (2) have any ideas how to remove the erroneous result in the first place (to this aim, I have tried smoothing the matrix and scaling the diagonal amount other things with no luck).