Cannot perform the operation {negative constant}.^{real affine}

Hello,
How can I add this varaible?
factor =eta if u>=0(charging)
factor =1/eta if u<=0(discharding)

I use Big M and by assuming factor=eta^(-1^B), B is a Binary variable:
u>= -M(1-B)
u<=+M(B)
but the main issue the CVX will not be Ok with having B in exponential power.
eta is the efficiency, If I assume eta=1 factor will be one and the problem will be convex.
Is there any way for my optimization to pick one of the two values for the factor-like factor is either 1/eta or eta without using binary variables.

It’s not clear what is input data and what are optimization (CVX) variables.

You should look at pow_p and inv_pos, and determine their applicability.

1 Like

The cvx variable is u and B (B is binary) and the input is eta.
Thank you for your guidance.

Is etanegative?

help pow_p

pow_p Positive branch of the power function.
pow_p(X,P) computes a convex or concave branch of the power function:
P < 0: pow_p(X,P) = X.^P if X > 0, +Inf otherwise
0 <= P < 1: pow_p(X,P) = X.^P if X >= 0, -Inf otherwise
1 <= P : pow_p(X,P) = X.^P if X >= 0, +Inf otherwise
Both P and X must be real.

Disciplined convex programming information:
    The geometry of pow_p(X,P) depends on the precise value of P,
    which must be a real constant:
             P < 0: convex  and nonincreasing; X must be concave.
        0 <= P < 1: concave and nondecreasing; X must be concave.
        1 <= P    : convex  and nonmonotonic;  X must be affine.
    In all cases, X must be real.
1 Like

No, eta is the efficiency and always positive.

Thanks

Why did you get the error {negative constant}.^{real affine}?

help inv_pos

inv_pos Reciprocal of a positive quantity.
inv_pos(X) returns 1./X if X is positive, and +Inf otherwise.
X must be real.

 For matrices and N-D arrays, the function is applied to each element.

  Disciplined convex programming information:
      inv_pos is convex and nonincreasing; therefore, when used in CVX
      specifications, its argument must be concave (or affine).
1 Like

because it is eta^(-1^B).

However, I need to linearize my model. I got another idea
factor=B1 (1/eta) + B2 eta
B1, B2 are binary and different. If B1=1 and B2=0, the factor will be 1/eta otherwise it will be eta.

To define that these two binary variables can not equal each other we use the following:
B1<=B2-1
OR
B1>=B2+1
I linearized my mode and add the new constraints using the Big M value and use MOSEK to solve the problem.

Thank you so much!!