norms is a useful CVX function, but it is irrelevant to the error at hand, which is that the argument of norm must be affine, which ri is not. The "illegal’ expression is a norm of a norm, which violates CVX’s rules. norms could however allow ri(j)=norm(Anchors(j,1:2)-X1’); to be pulled out of the for loop.
Fortunately, this can be reformulated to not have norm of norm. Just introduce ri_no_norm(j) as ri_no_norm(j)=Anchors(j,1:2)-X1'; And then use norm([2*ri_no_norm;yi-1],2)<=yi+1; I added ri_no_norm rather than changing ri, because ri is also used elsewhere in your program…
We donn’t know what function you want to express. Can you explain what you want to do, or show us your mathematical formulas? I guess what Dr.Stone were trying to say is ri_no_norm(j) >= norm(Anchors(j,1:2)-X1'); rather than ri_no_norm(j)=Anchors(j,1:2)-X1';.
expression ri_no_norm(2*n,1)
for j=1:n
ri_no_norm(2*j-1:2*j) = Anchors(j,1:2)'-X1;
end
You should be able to vectgorize this (reformulate it to not use for loop) if executing this for loop takes too long for you.
And the point of the reformulation to not use norm of norm is that the expression using norm with ri_no_norm` is mathematically equivalent to the norm of norm formulation, but it is accepted by CVX.