Thank you for your help so far. I am having trouble with an assignment in my code,
I have an expression ‘trq’, which is assigned in every step inside a loop inside constraints. The value I get for this expression is very different from the value I get if I run it after solving the problem(using the values in the end of solve), what could be the problem.

Upon CVX cimpletion, presuming it declares optimum, the optimal value is numerically populated in all CVX variables. However, the numerical values of expressions may not necessarily correspond to the optimum,. The true optimum is used internally so that the problem is correctly solved, but to be sure you have the correct optimal values, you have to compute the CVX expressions using the CVX (optimal) variable values after CVX completion.

So I understand the true values are the ones I can calculate after complete solve of the problem, but if I use this expression as a part of other equations, are they going to have the right values or they may have the same issue?

You have to compute whatever you want starting from the optimal variable values. If you use the value of an expression after CVX completes, without recomputing it from the optimal variable values, it may or may not have the correct value. However, CVX internally uses the correct values, i.e., the problem is solved correctly.

I am facing a problem with another assignment, I have an expression eff which is sum of a constant number and two quadratic terms (both positive convex), but I get convex programming error, Invalid operation: square( {convex} ), can you help me with that? Isn’t square of a convex term also convex?

variable v(k)
expression eff(k-1)
expression trq(k-1)
for i=1:k-1
eff(i) = p00 - (p10^2/4/p20) - (p01^2/4/p02) + (p_v2*v(i)+p10/2/p_v2)^2 + (p_t2*trq(i)+p01/2/p_t2)^2;
end

No. For instance, (x^2-1)^2 is concave for |x| < sqrt(1/3) Note that square_pos(x^2-1) is convex and is allowed by CVX; but that is a different function.

you are absolutely right, but in this case, the shape of the surface as it is shown below (it is convex) and I have the formulation on x and y (V and trq) with coefficients, is this form acceptable for CVX?

I am unable to determine that because you haven’t provided the input data, which is pertinent to the convexity or not of the expression in question. If your input data is such that the expression in question is convex, and that the term being squared is known (to you) to be nonnegative, then you can use square_pos instead of ^2 for the outer squaring, and CVX will accept that.