%% Obtain Optimal Objective Function Value
% Find both the location of the minimum of a nonlinear function and the value of the function at that minimum. The objective function is
% \[f(x) = x(1){e^{ - \left\| x \right\|_2^2}} + \left\| x \right\|_2^2/20\].

fun = @(x)x(1)*exp(-(x(1)^2 + x(2)^2)) + (x(1)^2 + x(2)^2)/20;

% Find the location and objective function value of the minimizer starting at x0 = [1,2].

x0 = [1,2];
[x,fval] = fminunc(fun,x0)

% Copyright 2019 The MathWorks, Inc.