%% Obtain Generated Function Details
% This example shows how to find the values of extra parameters in functions generated by prob2struct.
% Create a nonlinear problem and convert the problem to a structure using prob2struct. Name the generated objective function and nonlinear constraint function.

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];
problem = prob2struct(prob,x0,'ObjectiveFunctionName','rosenbrock',...
    'ConstraintFunctionName','circle2');

%
% Examine the first line of the generated constraint function circle2.

type circle2

% The circle2 function has a second input named extraParams. To find the values of this input, use the functions function on the function handle stored in problem.nonlcon.

F = functions(problem.nonlcon)

% To access the extra parameters, view the workspace field of F.

ws = F.workspace

% Continue to extract the information at deeper levels until you see all the extra parameters.

ws1 = ws{1}
ep = ws1.extraParams
ep{1}
ep{2}
ep{3}

% Now you can read the circle2 file listing and understand what all of the variables mean.
% Hineq = 2*speye(2);
% fineq = sparse([0;0]);
% rhsineq = -4;
% Copyright 2020 The MathWorks, Inc.