How to express "t*e^(x/t)-t" in CVX?

I have already added another variable "z" and constraint {x,t,z}==exponential(1) according to Solve optimization problems of exp function.

Then re-express the expression as “z-t”. However, an error occurs as "Illegal operation: {log-affine} - log(affine)". I do not know to solve this error?

Show us your code. This is trivial to implement with the exponential cone construct. Look at mcg’s post in the link you provided.

Important: Do not include t*e^(x/t)-t in your CVX code. The new variable and exponential cone construct in the link is instead of t*e^(x/t)-t, not in addition to it.

Thank you for your kind reply, Mark. My code is as follows:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

K=4;
N=50;
E_max=10^7;

cvx_expert true
cvx_power_warning
cvx_precision best
cvx_begin gp quiet 
% cvx_begin  quiet

variable l_loc(1,N)
variable l_off(1,N)
variable t_off(1,N)
variable z_off(1,N)
variable l_down(1,N)
variable t_down(1,N)

expression cvx_objfun
expression E_loc(1,N)
expression E_off(1,N)
expression E_down(1,N)

for n=1:1:N   
    E_loc(n)=l_loc(n)^3;      
    E_down(n)=l_down(n)^3/t_down(n)^2 ;
    E_off(n)=z_off(n)- t_off(n) ;  % E_off(n)= t_off(n)*exp( l_off(n)/t_off(n) )-t_off(n)
    
%     E_loc(n)=pow_p( l_loc(n),3 );
%     E_down(n)=pow_p(l_down(n),3)/t_down(n)^2 ;
%     E_off(n)=z_off(n)- t_off(n) ;  % E_off(n)= t_off(n)*exp( l_off(n)/t_off(n) )-t_off(n)
end

% % objective function
cvx_objfun=sum(l_loc ) + sum( l_off ) ;
maximize(cvx_objfun)
% % constraint function
subject to

for n=1:1:N
    l_off(n)>=0;
    t_off(n)>=0;
    E_loc(n)+E_off(n)+E_down(n)<=E_max;
    {l_off(n),t_off(n),z_off(n)}== exponential(1); % the added constraint for t_off(n)*exp( l_off(n)/t_off(n) )<=z_off(n)
    %     l_off(n)+rel_entr(t_off(n),z_off(n))<=0;
end

cvx_end
cvx_status

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

The problem is I have both ‘l_down(n)^3/t_down(n)^2’ and ‘t_off(n)*exp( l_off(n)/t_off(n) )’ in my constraints. If I use the command ‘cvx_begin gp quiet’, I will have an error like this:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Error using + (line 83)
Disciplined convex programming error:
Illegal operation: {log-affine} - {log-affine}

Error in - (line 21)
z = plus( x, y, true, cheat );

Error in Sample_Trajectory_CVX (line 31)
E_off(n)=z_off(n)- t_off(n) ; % E_off(n)= t_off(n)*exp(
l_off(n)/t_off(n) )-t_off(n)
%%%%%%%%%%%%%%%%%%%%%%%%%%%
However, if I use the command ’ cvx_begin quiet’, I will have the following error:
%%%%%%%%%%%%%%%%%%%%%%%%%%%
Error using cvx/pow_cvx (line 142)
Disciplined convex programming error:
Illegal operation: {real affine} .^ {3}
(Consider POW_P, POW_POS, or POW_ABS instead.)

Error in .^ (line 55)
z = pow_cvx( x, y, ‘power’ );

Error in ^ (line 9)
z = power( x, y );

Error in Sample_Trajectory_CVX (line 29)
E_loc(n)=l_loc(n)^3;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Then I changed the expressions as
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
E_loc(n)=pow_p( l_loc(n),3 );
E_down(n)=pow_p(l_down(n),3)/t_down(n)^2 ;
E_off(n)=z_off(n)- t_off(n) ; % E_off(n)= t_off(n)*exp( l_off(n)/t_off(n) )-t_off(n)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

I will get another error:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Error using .* (line 173)
Disciplined convex programming error:
Cannot perform the operation: {convex} ./ {convex}

Error in ./ (line 19)
z = times( x, y, ‘./’ );

Error in * (line 36)
z = feval( oper, x, y );

Error in / (line 15)
z = mtimes( x, y, ‘rdivide’ );

Error in Sample_Trajectory_CVX (line 34)
E_down(n)=pow_p(l_down(n),3)/t_down(n)^2 ;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

I do not know whether there is a way to satisfy the requirements for both ‘l_down(n)^3/t_down(n)^2’ and ’ t_off(n)*exp( l_off(n)/t_off(n) )-t_off(n)’.

Advice: Do not use quiet, expert, or turn off warnings until everything is working well.

Have you proven that your problem is convex? Please read Why isn't CVX accepting my model? READ THIS FIRST! . I will mark the problem as non-convex until such time as you prove that it is convex. I don’t like doing that,because the expression in the thread title is convex, presuming that x and t are CVX (optimization) variables, and marking the thread as non-convex seems to imply otherwise.

I have simplified my code:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
E_max=10^7;

% cvx_begin gp
cvx_begin

variable x1
variable t1
variable z
variable x2
variable t2
variable x3

expression E1
expression E2
expression E3

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
E1=z -t1; % E1= t1*exp( x1/t1 )-t1
E2=x2^3/t2^2 ;
E3=x3^3;

% E1=z -t1; % E1= t1*exp( x1/t1 )-t1
% E2=pow_p(x2/t2,3)*t2 ;
% E3=pow_p( x3,3 );

maximize(x1+x3)
subject to

x1>=0;
x2>=0;
x3>=0;
E1+E2+E3<=E_max;
{x1,t1,z}== exponential(1); % the added constraint for t1*exp( x1/t1 )<=z in E1
% x1+rel_entr(t1,z1)<=0;

cvx_end
cvx_status
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

I am sure it is convex, because there are mainly three expressions in the code: ‘E1= t1*exp( x1/t1 )-t1’,
'E2=x2^3/t2^2 ', ‘E3=x3^3’, and they are all convex. I have added another variable ‘z’ to re-express E1 as ‘E1= z-t1’ with an added constraint ‘{x1,t1,z}== exponential(1)’ .

However, the errors are still there: If I use the command ‘cvx_begin’, the expression of E2=x2^3/t2^2 encounter the error as follows:
%%%%%%%%%%%%%%%%%%%%%%
Error using cvx/pow_cvx (line 142)
Disciplined convex programming error:
Illegal operation: {real affine} .^ {3}
(Consider POW_P, POW_POS, or POW_ABS instead.)

Error in .^ (line 55)
z = pow_cvx( x, y, ‘power’ );

Error in ^ (line 9)
z = power( x, y );

Error in Sample_Trajectory_CVX (line 24)
E2=x2^3/t2^2 ;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

If I re-express the E2 as 'E2=pow_p(x2/t2,3)t2 ', the error will change as
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Error using .
(line 173)
Disciplined convex programming error:
Cannot perform the operation: {real affine} ./ {real affine}

Error in ./ (line 19)
z = times( x, y, ‘./’ );

Error in * (line 36)
z = feval( oper, x, y );

Error in / (line 15)
z = mtimes( x, y, ‘rdivide’ );

Error in Sample_Trajectory_CVX (line 28)
E2=pow_p(x2/t2,3)*t2 ;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Unfortunately, if I use the command ‘cvx_begin gp’, the expression of E1=z -t1 will encounter an error as follows:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Error using + (line 83)
Disciplined convex programming error:
Illegal operation: {log-affine} - {log-affine}

Error in - (line 21)
z = plus( x, y, true, cheat );

Error in Sample_Trajectory_CVX (line 23)
E1=z -t1; % E1= t1*exp( x1/t1 )-t1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Here: How can I write this kind of constraint in cvx there was an example of x^3/t^2. Maybe it helps.

1 Like