Error : Invalid constraint: {convex} <= {convex}

One of the constraints in my program reported an error. The constraint is as follows.

variables u(200) v(200) ...
subject to
    ......
    square_pos(inv_pos(u)) <= ur.^2 + 2*ur.*(u-ur) + 1/v0^2*(vr.^2 + 2*vr.*(v-vr))

ur and vr are given 200-dimensional vectors. v0 is scalar.
The output is: Disciplined convex programming error:
Invalid constraint: {convex} <= {convex}
In my opinion, The right-hand side of this inequality is affine, or it’s convex and it’s concave. So I can’t understand the error. How can I fix this?

Are you sure the error message pertains to that line of code?

If ur, v0, vr are all input data, as you say, then the RHS appears is affine in u and v.

Can you show a complete reproducible problem, with all input data? Maybe you can reduce 200 dimensions to 2 dimensions and still exhibit the error message?

Ok Mark, here is the complete code.

clc;clear;
N = 200; 
T = 100; 
tt = T/N; 
H = 100; 
Vmax = 40; 

u1x = -550; u1y = 20;
u2x = -400; u2y = 320;
u3x = 0; u3y = 260;
u4x = 450; u4y = 600;
u5x = 800; u5y = 120;
B = 10^6; 
C = 1000
I = 10^8
fmax = 0.3 * 10^9
fumax = 6 * 10^9
co = 200; 
ro = 1.225
A = 0.603
Utip = 200
d0 = 0.301
v0 = 6.2089
s0 = 0.0499
P0 = 225.79
Pi = 426.07
kk = 10^-28 
Pmax = 10; Pmin = 2;
P1 = Pmax; P2 = Pmax; P3 = Pmax; P4 = Pmax; P5 = Pmax; 
xI = -700; yI = 0; xF = 700; yF = 0; 
xr = (-700:7:700)'; yr = zeros(201,1); 
vr = zeros(200,1); 
for i=1:200
    vr(i) = norm([xr(i+1)-xr(i),yr(i+1)-yr(i)]) / tt;
end
ur = sqrt(sqrt(1+vr.^4/(4*v0^4)) - vr.^2/(2*v0^2))


cvx_begin
    variables fu1(200) fu2(200) fu3(200) fu4(200) fu5(200) f1(200) f2(200) f3(200) f4(200) f5(200) x(201) y(201) D1(200) D2(200) D3(200) D4(200) D5(200) u(200) j1(200) j2(200) j3(200) j4(200) j5(200) w1(200) w2(200) w3(200) w4(200) w5(200)
    expressions v(200) E1fly Ecomp euser
    for i=1:200
        v(i) = norm([x(i+1)-x(i),y(i+1)-y(i)]) / tt;
    end
    E1fly = tt * sum(P0*(1 + 3*square_pos(v)/Utip^2) + Pi*u + 0.5*d0*ro*s0*A*pow_pos(v,3))
    Ecomp = tt * kk * (sum(pow_pos(fu1,3)) + sum(pow_pos(fu2,3)) + sum(pow_pos(fu3,3)) + sum(pow_pos(fu4,3)) + sum(pow_pos(fu5,3)))
    euser = tt * kk * (sum(pow_pos(f1,3)) + sum(pow_pos(f2,3)) + sum(pow_pos(f3,3)) + sum(pow_pos(f4,3)) + sum(pow_pos(f5,3))) + sum(w1.*P1) + sum(w2.*P2) + sum(w3.*P3) + sum(w4.*P4) + sum(w5.*P5)
    minimize(E1fly + Ecomp + co*euser)
    subject to
        w1 + w2 + w3 + w4 + w5 <= tt %C1
        tt/C*sum(fu1+f1) >= I %C2,C3
        tt/C*sum(fu2+f2) >= I
        tt/C*sum(fu3+f3) >= I
        tt/C*sum(fu4+f4) >= I
        tt/C*sum(fu5+f5) >= I
        fu1 + fu2 + fu3 + fu4 + fu5 <= fumax %C4
        f1 <= fmax %C5
        f2 <= fmax
        f3 <= fmax
        f4 <= fmax
        f5 <= fmax
        v <= Vmax %C7
        x(1) == xI; x(201) == xF; y(1) == yI; y(201) == yF; %C9
        fu1(1) == 0; fu2(1) == 0; fu3(1) == 0; fu4(1) == 0; fu5(1) == 0; %C10
        w1(200) == 0; w2(200) == 0; w3(200) == 0; w4(200) == 0; w5(200) == 0; %C11
        w1 >= 0; w2 >= 0; w3 >= 0; w4 >= 0; w5>= 0; %C14
        fu1 >= 0; fu2 >= 0; fu3 >= 0; fu4 >= 0; fu5 >= 0; %C15
        f1 >= 0; f2 >= 0; f3 >= 0; f4 >= 0; f5 >= 0; %C16
        j1 >= 0; j2 >= 0; j3 >= 0; j4 >= 0; j5 >= 0; %C17
        u >= 0; %C18
        square_pos(inv_pos(u)) <= ur.^2 + 2*ur.*(u-ur) + 1/v0^2*(vr.^2 + 2*vr.*(v-vr)) %C15
cvx_end

Here is the output error messages.

错误使用 cvxprob/newcnstr (line 192)
Disciplined convex programming error:
   Invalid constraint: {convex} <= {convex}

出错  <=  (line 21)
b = newcnstr( evalin( 'caller', 'cvx_problem', '[]' ), x, y, '<=' );

出错 init1 (line 72)
        square_pos(inv_pos(u)) <= ur.^2 + 2*ur.*(u-ur) + 1/v0^2*(vr.^2 + 2*vr.*(v-vr)) %C15

The code in your first post is NOT!!! an extract of the complete code. Your first post showed that v is a variable, In your complete code, v is declared an expression, and its elements are set to norm(...) which are convex. That is why the RHS of the inequality is convex, not affine.

Although the RHS is affine with respect to v, it is not affine with respect to the the optimization variables. It is convex with respect to the optimization variables.

I will assume that constraint, and hence your problem, is non-convex unless you show otherwise.

Thank you Mark, now I understand why I got the errors. But how can I fix this? Can I turn v into a variable? I try to use v as a variable before, But I got another quesion. See how-can-i-express-this-constraint-in-dcp-ruleset

If you read the link I posted, you apparently didn’t understand it. Please read it carefully.

You are using norm in a non-convex way, on the RHS of a <= inequality. That is not allowed, and is not a convex constraint unless the RHS convex terms “net out” with something on the LHS.

Thank you Mark, I’ll read the post and try to improve my model.