# Disciplined convex programming error：Exponential multiplication

clc
clear all
close all
cvx_begin gp
variables x
object =(1-x)*exp(-x);
maximize object
subject to
0<x<1;
cvx_end
%%%%%%%%%%
Disciplined convex programming error:
Cannot perform the operation: {concave} ./ {log-convex}
%%%%%%%%%%%
Why can’t cvx recognize this form of multiplication?
How can it be solved?

Do you see that listed as being allowed in the gp rules http://cvxr.com/cvx/doc/gp.html? I don’t.

Your objective function is concave within your constraint region of 0 < x < 1; so maximization over that domain is inherently a non-convex optimization problem. Actually it is a concave programming problem with compact constraints; therefore, its global maximum occurs at an extreme of the constraints, i.e…, at 0 or 1, and it happens to be at 1.

Your objective function is concave for x > 3, but because it is not concave over the entirety of its natural domain, the prospects for formulating within DCP rules, even if the problem is constrained to x > 3, are not good.

How can I solve such problems?
I think CVX does not recognize the expression of the objective function object =(1-x)*exp(-x);

Thank you

This is a non-convex problem, which requires a non-convex solver (unless you can solve it by inspection or analytically, as I did with your very simple example). CVX can’t be used for this problem.

However, essentially of the stuff in https://docs.mosek.com/cheatsheets/conic.pdf can be done in CVX, one way or another. So some multiplicative combinations of x and exp or log are acceptable in certain uses.

I am using CVXR to solve a concave objective function. I have a one-dimensional decision variable (x) and the objective function is the summation of 2 natural logarithm terms in which the second term is exponential with different bases of “a and b” (e.g., a^x, b^x) where “a, b” are constants and x is my decision variable. My full objective function is: (-x*sum(ln(y))) + ln((1-x)/((a^(1-x))-(b^(1-x)))) where y is a given 1-D vector of data.

I can successfully code the first term, but I keep getting “Error in xmax^(1 - alpha): non-numeric argument to binary operator” when I add the second term having (a^x and b^x) to the objective. Here is my code:

library(CVXR)
a <- 7
b <- 0.3
M=1000
x_i # is a given vector of 1-D data

x <- Variable(1)
nominator <- (1-x)
denominator <- (1/((a^(1-x))-(b^(1-x))))
obj <- (-xsum(log(x_i)) + Mlog(nominator/denominator)) # change M to the length of X_i later
constr <- list(x>0)
prob <- Problem(Maximize(obj), constr)
result <- solve(prob)
alpha_hat <- result\$getValue(x)

I truly appreciate if you can help me with this and tell me what I am doing wrong.
Please post questions to the `cvx` tag on StackOverflow.