# Opt. pb with "reciprocal" variable

(Mario Di Mauro) #21

Actually, i need as output value a cvx_optval (function of \lambda and \mu) that varies in accordance to the constraint c (in order to produce a graph with c on x-axis). With the actual suggestion, the code would be something like this:

for c=cin:cstep:cfin
c_res=round(((cfin-(c-cstep))/cstep));
cvx_begin;
variables t(n) mou(n) s(n)
minimize(sum(t));
subject to
sum(s)<=c
{1,t,mou - lambda} == rotated_lorentz(1)
cvx_end
result(c_res)=cvx_optval;
end
stem(result)

It works but, ovbiously, it returns the same output for different c values.
Mario

(Mark L. Stone) #22

Where is the end statement which ends your for loop? You need to save the value of cvx_optval before the end of the for loop, so that each saved cvx_optval corresponds to the just completed cvx begin … cvx_end.

(Mario Di Mauro) #23

sorry…I missed the end statement for mistake. I’ve updated my previous post with the exact code.
The output is unchanged (cvx_optvalue is the same for all value of c)

Mario

(Mark L. Stone) #24

You didn’t include all of @Erling;s constraints. You need a for loop for this rotated lotentz constraint (for instance, look at my code above)… Plus thre’s another one.

And also, perhaps sum(s) <= cin winds up producing the same optimal solution as sum(s) <= cfin.