# How can I express this constraint in DCP ruleset?

the code is kind like this

``````cvx_begin
variables x(201) y(201) v(200)
subject to
for i=1:200
v(i) == norm([x1(i+1)-x1(i),y1(i+1)-y1(i)])
end
cvx_end
``````

the output will return an error:Disciplined convex programming error:
Invalid constraint: {real affine} == {convex}
so how to express variable v in DCP ruleset?

That is a nonlinear equality constraint, which is non-convex, and can’t be handled in CVX.

However, you haven’t shown us what you want to do with `v`.
Perhaps you want

``````expression v(20)
for i=1:200
v(i) = norm([x1(i+1)-x1(i),y1(i+1)-y1(i)]);
end
``````

and then use `v` in a convex manner. That uses assignment ( `=` ), not equality constraint ( `==` ), and is allowed by CVX’s DCP rules.

But maybe you just want the total variation norm, in which case, there is no need to declare or use an expression holder (array):: see my answer How to Formulate in CVX - 1D Total Variation Extension - #7 by Mark_L_Stone.

Thank you Mark! I think you solved my problem for now.