# Using Log function as a Constraint

Hello everyone;

I am trying to apply logarithmic function and exponential as a constraint, but CVX give me some errors.
My trials and errors are given below

exp(r(i,j)) <= 1000 + (M2* (1-U(j,i))); ==>“Unrecognized function or variable ‘last_act’.”
log(r(i,j)) <= 1000 + (M2* (1-U(j,i))); ==> “Illegal operation: log( {convex} )” (On CVX document, they stated that log function is used with concave )
exp(log(10)r(i,j)) <= 1000 + (M2 (1-U(j,i))); ==>“Unrecognized function or variable ‘last_act’.”

My main purpose is to implement :
*k is constant like 2,3,4…
*r(i,j) is calculated like a distance r(i,j)= norm()
***log10(r(i,j)^k) + r(i,j) <= const. **
** or **
*r(i,j)^k * 10^ r(i,j) <= const.

Thank you

I think the error with `last_act` may be due to a bug in whatever version of CVX you are using. if you are not using CVX 2.2, please switch to it. If you are using CVX 3.0beta, make sure to manually remove all CVX directories from the MATLAB path, save the updated path, close MATLAB, start a new MATLAB session, and run `cvx_setup` for CVX 2.2

As you have told us, CVX does not allow `log(convex_expression)`.

`log(convex_expression) <= constant`
you can enter
`convex_expression <= exp(constant)`
which CVX does allow (make sure the problem scaling is such that `exp(constant) ` is not a very big number, such as ``1e-5` or greater, oitherwise, the solver might encounter numerical difficulties).
Does that allow you to everything needed?

Dear Mark;
First of all, how can I learn which cvx version ı used? Is there any command for that?
Secondly I tried :
**U,xd,yd are defined as a variable
**r is defined as a expression

``````    r(i,j) = norm([ ( Uloc(i,1) - xd(j) ); ( Uloc(i,2) - yd(j))]);
r(i,j)*10^r(i,j) <= gamma_opt + (M2* (1-U(j,i)));
``````

In this case I got an error like “Disciplined convex programming error: Cannot perform the operation: {convex} .* {log-convex}”

How can I implement this constraint on CVX or do you have any recommendation for this?

`cvx_version`

Aside from some conversion factors, your expression is basically of the form
`norm(x)*exp(norm(x))`. I believe that is convex. I will leave it to you or one of the other forum readers to determine whether this can be handled in a similar manner to Lambert W-function in section 5.2.9 of Mosek Modeling Cookbook https://docs.mosek.com/modeling-cookbook/expo.html#modeling-with-the-exponential-cone , although perhaps with an extra step to deal with `norm(x)` rather than `x` as in the Lambert W-function.