1

I want to solve: enter image description here

I use following MATLAB code, but it does not work.

Can someone please guide me?

function f=objfun

f=-f;

function [c1,c2,c3]=constraint(x)
a1=1.1; a2=1.1; a3=1.1;
c1=f-log(a1)-log(x(1)/(x(1)+1)); 
c2=f-log(a2)-log(x(2)/(x(2)+1))-log(1-x(1)); 
c3=f-log(a3)-log(1-x(1))-log(1-x(2));


x0=[0.01;0.01]; 
[x,fval]=fmincon('objfun',x0,[],[],[],[],[0;0],[1;1],'constraint')
4
  • Your definition of objfun doesn't make any sense to me... Commented Nov 19, 2015 at 3:21
  • Does not work means nothing. What specifically is wrong? Commented Nov 19, 2015 at 3:22
  • how can I define obtfun' since it is not function of x'? Thats the place I am struggling. Commented Nov 19, 2015 at 3:27
  • Replace T for x3 and it should make sense. T is just another choice variable. Commented Nov 19, 2015 at 4:19

2 Answers 2

3

You need to flip the problem around a bit. You are trying to find the point x (which is (l_1,l_2)) that makes the minimum of the 3 LHS functions the largest. So, you can rewrite your problem as, in pseudocode,

maximise, by varying x in [0,1] X [0,1]
       min([log(a1)+log(x(1)/(x(1)+1)) ...
            log(a2)+log(x(2)/(x(2)+1))+log(1-x(1)) ...
            log(a3)+log(1-x(1))+log(1-x(2))])

Since Matlab has fmincon, rewrite this as a minimisation problem,

minimise, by varying x in [0,1] X [0,1]
       max(-[log(a1)+log(x(1)/(x(1)+1)) ...
             log(a2)+log(x(2)/(x(2)+1))+log(1-x(1)) ...
             log(a3)+log(1-x(1))+log(1-x(2))])

So the actual code is

F=@(x) max(-[log(a1)+log(x(1)/(x(1)+1)) ...
             log(a2)+log(x(2)/(x(2)+1))+log(1-x(1)) ...
             log(a3)+log(1-x(1))+log(1-x(2))])
[L,fval]=fmincon(F,[0.5 0.5])

which returns

L =
    0.3383    0.6180
fval =
    1.2800
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks @David !!! When I run your code, it says FMINCON requires at least four input arguments. is something missing in your code?
That's weird, all I have extra is the line a1=1.1;a2=1.1;a3=1.1;.
You must have a different version of Matlab, I have 2015a here. fmincon should take more than 2 arguments, it does contrained optimisation, so it should require constraints I guess. Try this instead: [L,fval]=fmincon(F,[0.5 0.5],[],[],[],[],[0 0],[1 1]).
Thanks @David !!! It really helps, and I actually need this problem for any N number of constraints. I have already tried for three, and it works: [x,fval]=fmincon(F,[0.5 0.5 0.5],[],[],[],[],[0;0;0],[1;1;1]). Have a great day !!! BTW do you have any idea of modifying my approach, just curious, but not necessary :)
Yeah that's the right approach for more L's, for more constraints you only need to change the F by adding a new row for the new constraint.
0

Can also solve this in the convex optimization package CVX with the following MATLAB code:

cvx_begin
 variables T(1);
 variables x1(1);
 variables x2(1);

 maximize(T)
 subject to:
  log(a1) + x1 - log_sum_exp([0, x1]) >= T;
  log(a2) + x2 - log_sum_exp([0, x2]) + log(1 - exp(x1)) >= T;
  log(a3) +  log(1 - exp(x1)) +  log(1 - exp(x2)) >= T;
  x1 <= 0;
  x2 <= 0;
cvx_end
l1 = exp(x1); l2 = exp(x2);

To use CVX, each constraint and the objective function has to be written in a way that is proveably convex using CVX's ruleset. Making the substitution x1 = log(l1) and x2 = log(l2) allows one to do that. Note that: log_sum_exp([0,x1]) = log(exp(0) + exp(x1)) = log(1 + l1)

This also returns the answers: l1 = .3383, l2 = .6180, T = -1.2800

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.