optimize

Updated:


optimize is the common function for solving optimization problems.

Syntax

diagnostics = optimize(Constraints,Objective,options)

Examples

A linear program can be solved with the following piece of code

x = sdpvar(length(c),1);
F = [A*x<=b];
h = c'*x;
optimize(F,h);
solution = value(x);

If we only look for a feasible solution, we can omit the objective function

optimize(F);

A diagnostic structure is returned which can be used, e.g, to check feasibility as reported by the solver (see yalmiperror for the possible return values)

diagnostics = optimize(F);
if diagnostics.problem == 0
 disp('Solver thinks it is feasible')
elseif diagnostics.problem == 1
 disp('Solver thinks it is infeasible')
else
 disp('Something else happened')
end

Solving the feasibility problem with a particular solver, e.g. QUADPROG, can be done by creating an options structure with sdpsettings

options = sdpsettings('solver','quadprog')
optimize(F,[],options);

Minimization is assumed, hence if we want to maximize, we simply flip the sign of the objective.

optimize(F,-h);