I have implemented my own matrix library in Java to solve fluid simulations. So I have also implemented the conjugate gradient method and I got a little bit confused.

What I have done to test my CG-method is the following:

- Generate M, a $ n\times n$ matrix, initialized with values between 0 and 1 (exclusive)
- Calculate $ A = M \cdot M^T$ (which must be symmetric positive definite)
- Calculate the conjugate gradient and display the residuum and the actual distance to the target (I used cholesky to solve the equation and get an exact solution).

My results have been the following (n = 10):

`residuum: actual distance: 0.9199326513658944 72.7313310733776 0.7300075150837726 72.24654586114522 1.2209457036576696 69.71996519380937 2.062353336085214 50.76028746131138 0.5685046122325719 44.90515825964432 0.6994645262755821 43.72541529795878 0.6572329365491988 33.37442078957705 1.0192100131027082 18.410526779358293 1.0808876324653045 4.531060524696579 0.19130828691828886 4.436357203678213 3.423483345725764E-10 1.8117326798071072E-10 `

- Why does the actual distance always decrease but the residuum does not?
- Why is the distance so big to begin with? Is there a way to scale the Matrix or the vector to reduce A) the amount of steps required B) reduces the distance?