Why the code doesn't work?

Have you proven this is a convex optimization problem? The 2nd term of the objective function summand can be implemented per the last row of the table in section “5.2.10 Other simple sets” of 5 Exponential cone optimization — MOSEK Modeling Cookbook 3.3.0 . I haven’t verified the curvature one way or another for the first term of the objective function summand. Have you?

Instead of declaring the same scalar variable Pj N each time through a for loop, you need to declare it once as a vector
variable Pj(N)

That will be moot if you don’t prove convexity.