%% Linear Inequality and Equality Constraint
% Find the minimum value of Rosenbrock's function when there are both a linear inequality constraint and a linear equality constraint.
% Set the objective function fun to be Rosenbrock's function.

fun = @(x)100*(x(2)-x(1)^2)^2 + (1-x(1))^2;

%
% Find the minimum value starting from the point [0.5,0], constrained to have x(1) + 2x(2) \le 1 and 2x(1) + x(2) = 1.
% Express the linear inequality constraint in the form A*x <= b by taking A = [1,2] and b = 1.
% Express the linear equality constraint in the form Aeq*x = beq by taking Aeq = [2,1] and beq = 1.

x0 = [0.5,0];
A = [1,2];
b = 1;
Aeq = [2,1];
beq = 1;
x = fmincon(fun,x0,A,b,Aeq,beq)

% Copyright 2015 The MathWorks, Inc.