We have a large sparse symmetric positive-definite matrix $A \in \mathbb R^{N \times N}$ and a vector $x \in \mathbb R^N$. How do I practically compute the inner product $x^T A x$ when the matrix $A$ is ill-conditioned?
In my applications, this is a stiffness or mass matrix of a finite element code.
There is an obvious algorithm that first computes $y = A x$ and then the dot product $x^T y$. However, this product occasionally happens to be negative in my computations. That cannot be in exact arithmetic but it happens in the presence of rounding errors.
I am wondering how that can be mitigated.