%% Minimize with Bound Constraints
% Find the minimum of an objective function in the presence of bound constraints.
% The objective function is a simple algebraic function of two variables.

fun = @(x)1+x(1)/(1+x(2)) - 3*x(1)*x(2) + x(2)*(1+x(1));

% Look in the region where x has positive values, x(1) \le 1, and x(2) \le 2.

lb = [0,0];
ub = [1,2];

% There are no linear constraints, so set those arguments to [].

A = [];
b = [];
Aeq = [];
beq = [];

% Try an initial point in the middle of the region.

x0 = (lb + ub)/2;

% Solve the problem.

x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub)

% A different initial point can lead to a different solution.

x0 = x0/5;
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub)

% To determine which solution is better, see Obtain the Objective Function Value.
% Copyright 2019 The MathWorks, Inc.