%% Convert Nonlinear Problem to Structure
% Create a nonlinear problem in the problem-based framework.

x = optimvar('x',2);
fun = 100*(x(2) - x(1)^2)^2 + (1 - x(1))^2;
prob = optimproblem('Objective',fun);
mycon = dot(x,x) <= 4;
prob.Constraints.mycon = mycon;
x0.x = [-1;1.5];

% Convert prob to an optimization problem structure. Name the generated objective function file 'rosenbrock' and the constraint function file 'circle2'.

problem = prob2struct(prob,x0,'ObjectiveFunctionName','rosenbrock',...
    'ConstraintFunctionName','circle2');

% prob2struct creates nonlinear objective and constraint function files in the current folder. To create these files in a different folder, use the 'FileLocation' name-value pair.
% Solve the problem.

[x,fval] = fmincon(problem)

% Copyright 2018 The MathWorks, Inc.