How to write this with CVX code

Have you formulated a convex optimization problem? That is your responsibility. Perhaps you need to reread, very carefully, the link previously provided.

You might find the material in Convex Optimization – Boyd and Vandenberghe to be of assistance. For example, Exercise 7.4. Or you might not.