%% Create Expression from Nonlinear Function
% Create an optimization expression corresponding to the objective function
% f(x) = x^2/10 + \exp(-\exp(-x)).

x = optimvar('x');
f = x^2/10 + exp(-exp(-x))

% Find the point that minimizes fun starting from the point x0 = 0.

x0 = struct('x',0);
prob = optimproblem('Objective',f);
[sol,fval] = solve(prob,x0)

% If f were not a supported function, you would convert it using fcn2optimexpr. See Supported Operations on Optimization Variables and Expressions and Convert Nonlinear Function to Optimization Expression.

f = @(x)x^2/10 + exp(-exp(-x));
fun = fcn2optimexpr(f,x)
prob = optimproblem('Objective',fun);
[sol,fval] = solve(prob,x0)

% Copyright 2018–2020 The MathWorks, Inc.