MATLAB: Constraint optimization with alternatives under specific conditions

constrained optimizationfminconoptimization

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.

Best 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.