%% Use a Problem Structure
% Solve the same problem as in Nondefault Options using a problem structure instead of separate arguments.
% Create the options and a problem structure. See problem for the field names and required fields.

options = optimoptions('fmincon','Display','iter','Algorithm','sqp');
problem.options = options;
problem.solver = 'fmincon';
problem.objective = @(x)100*(x(2)-x(1)^2)^2 + (1-x(1))^2;
problem.x0 = [0,0];

% The nonlinear constraint function unitdisk appears at the end of this example. Include the nonlinear constraint function in problem.

problem.nonlcon = @unitdisk;

% Solve the problem.

x = fmincon(problem)

% The iterative display and solution are the same as in Nondefault Options.
%
% The following code creates the unitdisk function.

function [c,ceq] = unitdisk(x)
c = x(1)^2 + x(2)^2 - 1;
ceq = [];
end

% Copyright 2019 The MathWorks, Inc.