Yet further gains may be made by using a technique known as preconditioning. ``Preconditioning'' basically means applying an operator to your gradient in order to make the search direction point more toward the minimum. To implement this, the only changes to your code are in the formation of your search direction.
If we call the preconditioning operator K(), then the only changes you need to make appear in the code fragment below:
if (i<10)
dir=(-1.)*K(grad);
else {
beta= ...
dir=beta*dir+(-1.)*K(grad);
}
The formula for
for preconditioned conjugate-gradients now becomes
Make these changes for preconditioning to your main() program.