Função Matlab: Fmincon
Função Matlab: Fmincon
linear constraints
C(x) 0
Ceq(x) = 0
LB x UB
(nonlinear constraints)
bounding of variables
Common Syntax:
x = fmincon(fun, x0, A, b)
x = fmincon(fun, x0, A, b, Aeq, Beq)
x = fmincon(fun, x0, A, b, Aeq, Beq, lb, ub)
x = fmincon(fun, x0, A, b, Aeq, Beq, lb, ub, nonlcon)
[x, fval, exitflag, output, lambda] = fmincon(fun, x0, A, b, Aeq, Beq, lb, ub,
nonlcon)
where x0 is the initial guess for the minimum, nonlcon is an M-file function call for the
nonlinear constraints and defines C(x) and Ceq(x) . Note that if any argument is not
present, it should be set to a null set []. If lb and ub are not known, they should be set to
null sets as well. Lambda is the Lagrange multipliers.
Example 1:
Minimize
f(x) = x1x2x3
s.t.
0 x1 + 2x2 + 2x3 72
x0 = [10 10 10]T
Rewrite the linear inequality constraints as:
x1 2x2 2x3 0
12.0000
12.0000
fval =
3.456e+03
Example 2:
Minimize
x0 = [1 1]T
Write an M-file for the objective function:
function f = objfun(x)
f = exp(x(1))*(4*x(1)^2+2*x(2)^2+4*x(1)*x(2)+2*x(2)+1);
Write an M-file for the nonlinear constraints:
function [c, ceq] = confun(x)
c = [1.5+x(1)*x(2) x(1) x(2); x(1)*x(2) 10];
ceq = [];
The MATLAB input is:
>> x0 = [1; 1];
>> [x, fval] = fmincon(@objfun, x0, [], [], [], [], [], [], @confun)
x=
9.5474
1.0474
fval =
0.0236