Fix usage of A_kr in potential energy calculations.

Only use the first p columns in A_kr when calculating potential energy
and generalized active forces from potential energy.
Add Exercise 9.8.
Fix potential energy calculation.

Improve equality checking of partial derivatives.
Add Exercise 9.9.