constraint optimization with alternatives under specific conditions

0
down vote
favorite
I have the following optimization problem.
I'm using matlab to optimize a and b using fmincon function. I can define a and b as bound constraints but I'm confused where should I define the function c and d.
Thanks in advance for any help and/or clue. PS: I'm not sure if fmincon is okay for this kind of problem.

 Accepted Answer

Use this objective function for fmincon:
function f = objective(vec,x,y,z)
a=vec(1);
b=vec(2);
if 2*x*a-y*b-z >=4
c=1;
elseif 2*x*a-y*b-z < 0
c=0;
else
c=(2*x*a-y*b-z)/2;
end
if x*c-y*b-z >=2
d=1;
elseif x*c-y*b-z < 0
d=0;
else
d=(x*c-y*b-z)/2;
end
f = -(a*c*x+b*d*y+z);
end
and call fmincon as
x=...;
y=...;
z=...;
X=fmincon(@(vec)objective(vec,x,y,z),[0.5 0.5],[],[],[],[],[0 0],[1 1]);
Best wishes
Torsten.

1 Comment

Thanks a lot. The problem is solved now with your answer.
Regards, Viz

Sign in to comment.

More Answers (1)

Your problem looks straightforward enough for fmincon. You simply have to write your nonlinear constraints appropriately.
You need to define your variables as a single vector, usually called x. For example,
a = x(1);
b = x(2);
c = x(3);
d = x(4);
xx = x(5); % I write xx for your original x
y = x(6);
z = x(7);
Then your objective function becomes
@(x)-(x(1)*x(3)*x(5)+x(2)*x(4)*x(6)+x(7));
I write the negative of what you wrote as an objective function because you want to maximize the objective.
It is straightforward to write your nonlinear equality constraints in terms of x as well.
Start fmincon at a reasonable initial point and I believe that you will quickly arrive at an answer.
Alan Weiss
MATLAB mathematical toolbox documentation

3 Comments

Hi Alan, Thanks for your reply. My concern is how to define c and d. You wrote c = x(3) and d = x(4) but in the problem there are no explicit values of x(3) and x(4). These are defined by x(1), x(2), x(5), x(6) and x(7). I'm confused about where to define them ? Thanks for your time and help. Viz
x,y and z are given constants ?
Best wishes
Torsten.
hi Torsten, Yes x, y, z are given constants.

Sign in to comment.

Asked:

on 12 Jan 2016

Edited:

on 12 Jan 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!