Create p_matrix