GeneratePmatrix function

Generates the P-matrix