Choose an optimization solver. Create an objective function, typically the function you want to minimize. Create constraints, if any. Set options, or use the default options. Call the appropriate solver.For a basic nonlinear optimization example, see Solve a Constrained Nonlinear Problem.
Constraints: c(x) <= 0 or ceq(x)=0.
This example includes only an inequality constraint, so you must pass an empty array [] as the equality constraint function ceq.
function [c,ceq] = unitdisk(x) c = x(1)^2 + x(2)^2 - 1; ceq = [ ];
options = optimoptions(@fmincon,... 'Display','iter','Algorithm','interior-point');
[x,fval] = fmincon(rosenbrock,[0 0],... [],[],[],[],[],[],@unitdisk,options)The six sets of empty brackets represent optional constraints that are not being used in this example. See the fmincon function reference pages for the syntax.
MATLAB outputs a table of iterations and the results of the optimization.
Local minimum found that satisfies the constraints.
Optimization completed because the objective function is non-decreasing in
feasible directions, to within the selected value of the function tolerance,
and constraints are satisfied to within the selected value of the constraint tolerance.
x = 0.7864 0.6177 fval = 0.0457