# How to Define the Absolute function in the Constraint of SDP

Hi folks,

As you can see the fourth constraint has an absolute value. When I use abs(.) function, CVX makes an error:

Error using cvxprob/newcnstr
Disciplined convex programming error:
Invalid constraint: {real affine} <= {convex}
Error in <= (line 21)
b = newcnstr( evalin( ‘caller’, ‘cvx_problem’, ‘[]’ ), x, y, ‘<=’ );

I would appreciate it if you could help me to solve this problem.

The below is my complete code:

cvx_solver sdpt3
cvx_begin SDP
cvx_precision best
variables theta(6,1) U(7,7)
variable Z(6,6) symmetric
minimize (trace(G*U));
subject to
diag(Z) >= 0;
Z(5,5) == trace(Z(1:2,1:2))-2*theta(1:2)'*Xt(:,1)+norm(Xt(:,1))^2;
Z(6,6) <= trace(Z(3:4,3:4))-2*theta(3:4)'*Xtdot(:,1)+norm(Xtdot(:,1))^2;
Z(5,6) <= trace(Z(1:2,3:4))-theta(1:2)'*Xtdot(:,1)-theta(3:4)'*Xt(:,1)+Xtdot(:,1)'*Xt(:,1);
U == [Z , theta ; theta' , 1];
U == semidefinite(7);
cvx_end
cvx_status

Are you sure that code is the version you used when the error message was generated? I don’t see abs or as convex expression on the RHS of any ineqyuality.

You code looks like it should be accepted by CVX, although it might not necessarily correctly correspond to the problem you want to solve.

Also, never use cvx_precision high n CVX. That capability was provided with the best of intentions, but it is not a good thing to do, Just stick with the default for precision.,
I think it would be better to not declare U as a variable in conjunction with U = [Z , theta ; theta' , 1]; rather than U = [Z , theta ; theta’ , 1]; .

CVX can only handle convex problems. For SDP, that means linear SDP. If you have a nonlinear or otherwise non-convex SDP which can’t be reformulated as a linear SDP, then try YALMIP, which does support nonlinear SDPs.

Thank you very much. Yes, you are right. I forgot to put the abs() function. Actually, the code works without the abs() function in the fourth constraint. If we put absolute function as follows:
Z(5,6) <= abs(trace(Z(1:2,3:4))-theta(1:2)’*Xtdot(:,1)-theta(3:4)’*Xt(:,1)+Xtdot(:,1)’*Xt(:,1));

then the error will appear.

I tried to compact my code in this post. However, the complete code is as follows that can be run entirely. Please just consider the optimization section, i.e., “CVX Solver” and “YILMAP solver”, of the code and ignore the first part. As you can see, I also tried to solve with YALMIP, but it does not work!

I also trest your suggestion:

1. When I removed precision of the CVX, it can not solve!
2. When I define the U as an expression instead of variable, it become infeasible!

Thank you for your help.

%% Test code
clear
close all
format long
warning off

%% CVX Solver
G = [A’*A , -A’*b ; -b’A , b’b];
cvx_clear
% cvx_solver sedumi
% cvx_solver mosek
% cvx_solver sdpt3
cvx_begin SDP quiet
cvx_precision best
variables theta(8,1) U(9,9)
variable Z(8,8) symmetric
minimize (trace(G
U));
subject to
diag(Z) >= 0; Z(5,6) >= 0;
Z(5,5) == trace(Z(1:2,1:2))-2
theta(1:2)‘Xt(:,1)+norm(Xt(:,1))^2;
Z(6,6) == trace(Z(1:2,1:2))-2
theta(1:2)‘Xr(:,1)+norm(Xr(:,1))^2;
Z(7,7) <= abs(trace(Z(3:4,3:4))-2
theta(3:4)‘Xtdot(:,1)+norm(Xtdot(:,1))^2);
Z(8,8) <= abs(trace(Z(3:4,3:4))-2
theta(3:4)’*Xrdot(:,1)+norm(Xrdot(:,1))^2);
Z(5,7) <= abs(trace(Z(1:2,3:4))-theta(1:2)’*Xtdot(:,1)-theta(3:4)’*Xt(:,1)+Xtdot(:,1)’*Xt(:,1));
Z(6,8) <= abs(trace(Z(1:2,3:4))-theta(1:2)’*Xrdot(:,1)-theta(3:4)’*Xr(:,1)+Xrdot(:,1)‘Xr(:,1));
Z(5,6) >= abs(trace(Z(1:2,1:2))-theta(1:2)’
(Xt(:,1)+Xr(:,1))+Xt(:,1)’*Xr(:,1));
Z(5,8) <= abs(trace(Z(1:2,3:4))-theta(1:2)’*Xrdot(:,1)-theta(3:4)’*Xt(:,1)+Xt(:,1)’*Xrdot(:,1));
Z(6,7) <= abs(trace(Z(1:2,3:4))-theta(1:2)’*Xtdot(:,1)-theta(3:4)’*Xr(:,1)+Xr(:,1)‘Xtdot(:,1));
Z(7,8) <= abs(trace(Z(3:4,3:4))-theta(3:4)’
(Xtdot(:,1)+Xrdot(:,1))+Xtdot(:,1)’*Xrdot(:,1));

U == [Z , theta ; theta' , 1];
U == semidefinite(9);

cvx_end
cvx_status
% cvx_solver
Xhat_SDP = theta(1:2);
Xhatdot_SDP = theta(3:4);

%% YALMIP Solver
yalmip(‘clear’)

% Define Variables
theta1 = sdpvar(8,1);
U1 = sdpvar(9,9,‘symmetric’);
Z1 = sdpvar(8,8,‘symmetric’);

% Define Constraints
% my_tolerance_for_strict = 1e-5;
Constraints = [U1>=0 , U1 == [Z1 , theta1 ; theta1’ , 1] , …
diag(Z1) >= 0 , Z1(5,6) >= 0 , …
Z1(5,5) == trace(Z1(1:2,1:2))-2*theta1(1:2)‘Xt(:,1)+norm(Xt(:,1))^2, …
Z1(6,6) == trace(Z1(1:2,1:2))-2
theta1(1:2)‘Xr(:,1)+norm(Xr(:,1))^2, …
Z1(7,7) <= trace(Z1(3:4,3:4))-2
theta1(3:4)‘Xtdot(:,1)+norm(Xtdot(:,1))^2, …
Z1(8,8) <= trace(Z1(3:4,3:4))-2
theta1(3:4)’*Xrdot(:,1)+norm(Xrdot(:,1))^2, …
Z1(5,7) <= trace(Z1(1:2,3:4))-theta1(1:2)’*Xtdot(:,1)-theta1(3:4)’*Xt(:,1)+Xtdot(:,1)’*Xt(:,1), …
Z1(6,8) <= trace(Z1(1:2,3:4))-theta1(1:2)’*Xrdot(:,1)-theta1(3:4)’*Xr(:,1)+Xrdot(:,1)‘Xr(:,1), …
Z1(5,6) >= trace(Z1(1:2,1:2))-theta1(1:2)’
(Xt(:,1)+Xr(:,1))+Xt(:,1)’*Xr(:,1), …
Z1(5,8) <= trace(Z1(1:2,3:4))-theta1(1:2)’*Xrdot(:,1)-theta1(3:4)’*Xt(:,1)+Xt(:,1)’*Xrdot(:,1), …
Z1(6,7) <= trace(Z1(1:2,3:4))-theta1(1:2)’*Xtdot(:,1)-theta1(3:4)’*Xr(:,1)+Xr(:,1)‘Xtdot(:,1), …
Z1(7,8) <= trace(Z1(3:4,3:4))-theta1(3:4)’
(Xtdot(:,1)+Xrdot(:,1))+Xtdot(:,1)’*Xrdot(:,1)]

Objective = trace(G*U1);
sol = optimize(Constraints,Objective);

All the constraints containing ab are non-convex, because abs is the only nonlinear (in the optimization variables) thing on either side of the <= So no reformulation to convex would be possible, unless it turned out that all the constraints were redundant and could be eliminated, which I presume is not the case.

Unfortunately, your topic has earned the dreaded nonconvex categorization for the first time in a while.