code to compute total matter P(k)