I need to solve the following problem:

enter image description here

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.



2 Answers 2


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];

ans =


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;
  y = x*log(x);

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

  • $\begingroup$ 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 ! $\endgroup$
    – Mr Y
    Commented Dec 24, 2013 at 15:28
  • $\begingroup$ It's free users.isy.liu.se/johanl/yalmip $\endgroup$ Commented Dec 24, 2013 at 16:18

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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.