4
$\begingroup$

Given the following problem \begin{align}\min&\quad x_1+2x_2+3x_3+4x_4+\sum_{i=1}^4x_i\ln(x_i)\\\text{s.t.}&\quad e^\top x=1\\&\quad x\geq0\end{align}

I was asked to solved the dual problem and I think I've managed to do so, I've got $$q(\lambda)=-e^{-\lambda}(e^{-2}+e^{-3}+e^{-4}+e^{-5})-\lambda.$$ I wanted to check if I'm right so I wanted to check with CVX via matlab but the following code doesn't work.

cvx_begin  
variable x(4)
minimize (x(1)+2*x(2)+3*x(3)+4*x(4)+x(1)*log(x(1))+x(2)*log(x(2))+x(3)*log(x(3))+x(4)*log(x(4)))
sum(x)==1
x>=0

How can I fix the objective function? (I know the problem is at $x_i\ln(x_i)$)

$\endgroup$

1 Answer 1

5
$\begingroup$

Use CVX's entr function.

$\sum_{i=1}^ 4x_i\ln(x_i)$ can be entered as -sum(entr(x))

entr   Scalar entropy.
    entr(X) returns an array of the same size as X with the unnormalized
    entropy function applied to each element:
                 { -X.*LOG(X) if X > 0,
       entr(X) = { 0          if X == 0,
                 { -Inf       otherwise.
    If X is a vector representing a discrete probability distribution, then
    SUM(entr(X)) returns its entropy.
 
    Disciplined convex programming information:
        entr(X) is concave and nonmonotonic in X. Thus when used in CVX
        expressions, X must be real and affine. Its use will effectively 
        constrain X to be nonnegative: there is no need to add an
        additional X >= 0 to your model in order to enforce this.
$\endgroup$
0

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.