%% Examine Problem-Based Setup
% Examine the various stages of problem construction for optimizing the Rosenbrock function confined to the unit disk (see Solve a Constrained Nonlinear Problem, Problem-Based).
% Create a 2-D optimization variable x. Show the variable.

x = optimvar('x',2);
show(x)

% Create an expression for the objective function. Show the expression.

obj = 100*(x(2) - x(1)^2)^2 + (1 - x(1))^2;
show(obj)

% Create an expression for the constraint. Show the constraint.

cons = x(1)^2 + x(2)^2 <= 1;
show(cons)

% Create an optimization problem that has obj as the objective function and cons as the constraint. Show the problem.

prob = optimproblem("Objective",obj,"Constraints",cons);
show(prob)

% Finally, create an initial point [0 0] and solve the problem starting at the initial point.

x0.x = [0 0];
[sol,fval,exitflag] = solve(prob,x0)

% Examine the solution point.

sol.x

% Copyright 2019 The MathWorks, Inc.