%% Minimize a Polynomial
% Minimize the function \[f(x) = 3x_1^2 + 2{x_1}{x_2} + x_2^2 - 4{x_1} + 5{x_2}\].
% To do so, write an anonymous function fun that calculates the objective.

fun = @(x)3*x(1)^2 + 2*x(1)*x(2) + x(2)^2 - 4*x(1) + 5*x(2);

% Call fminunc to find a minimum of fun near [1,1].

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

% Copyright 2019 The MathWorks, Inc.