I have been doing some simple Mahalanobis distance problems by hand and checking my answers in the back of the book. Things were going well, so I decided to try and write a simple program to calculate it for a real data set using my statistics software. Equation I use is:
$$ d(x,y) = \sqrt{(x-y)^\top \Sigma^{-1}(x-y)} $$
The problem is, after I take the inner product of the terms inside the square root I get a negative value -- at which point my software throws an error. It's not totally clear how to trouble shoot this. My hunch was that I used the wrong representation for the variance covariance matrix (my software has a built-in functionality for variance covariance matrix), but after double checking, it seems to be correct. If I'm not mistaken, the variance covariance matrix can have negative values.
My Question: Does the Mahalanobis formula have a protocol for this? Or is this a sign I did something terribly wrong in my calculations?