constraint optimization with alternatives under specific conditions

1 view (last 30 days)
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

Torsten
Torsten on 12 Jan 2016
Edited: Torsten on 12 Jan 2016
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.

More Answers (1)

Alan Weiss
Alan Weiss on 12 Jan 2016
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
Vizimax
Vizimax on 12 Jan 2016
Edited: Vizimax on 12 Jan 2016
hi Torsten, Yes x, y, z are given constants.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!