# minimize function with convex constraints

I need to solve the following problem:

For a given p=(x0,y0,z0,w0) and arbitrary T. For example , let p=(0.8,0.1,0.06,0.04) and T=-1.2. I need to find a vector q=(x,y,z,w) with the minimum distance from p, under the given constraints.

I need a numerical solution, I tried using MATLAB but I had a lot of problems with that. I will be glad for some help / ideas.

Thanks!

I tried it (using YALMIP (disclaimer, developed by me))

x0 = [0.8,0.1,0.06,0.04]';
x = sdpvar(4,1);
objective = (x-x0)'*(x-x0);
constraints = [sum(x)==1, x>=0, sum(x.*log(x)) <= -1.2];
solvesdp(constraints,objective,sdpsettings('solver','fmincon'))
double(x)

ans =

5.356398659440911e-01
1.666760280554157e-01
1.522838063170345e-01
1.454002996834589e-01


Absolutely no problems for fmincon to solve the problem. Your statement "a lot of problems" is a bit vague. My guess is that you are not being careful with the definition of the entropy at zero, i.e., you cannot compute xlog(x) directly, you have to check for zero and return the analytic value there, as you will get 0*(-inf)=NaN otherwise

if x==0
y = 0;
else
y = x*log(x);
end


Some versions of fmincon might even require a safeguard against negative values of x, but the version above is an absolute minimum.

• Thanks for the answer. I checked and the entropy in 0 was one of my problems (well, I am pretty suck at programming...). Is that possible to buy/download your program YALMIP? ( I am a student so I have MATLAB's student edition, if that matters). In addition, do you have any recommended sources to learn how to do that kind of calculation ? Thanks again ! – Mr Y Dec 24 '13 at 15:28
• It's free users.isy.liu.se/johanl/yalmip – Johan Löfberg Dec 24 '13 at 16:18

I guess you could well use CVX package to minimize that in MATLAB: http://cvxr.com/cvx/