Page 364 - Applied Numerical Methods Using MATLAB
P. 364
MATLAB BUILT-IN ROUTINES FOR OPTIMIZATION 353
Usage of the MATLAB 6.x built-in function “fmincon()”
[xo,fo,.] = fmincon(’ftn’,x0,A,b,Aeq,beq,l,u,’nlcon’,options,p1,p2,.)
ž Input Arguments (at least four input arguments ’ftn’,x0,A and b required)
’ftn’ : an objective function f(x) to be minimized, usually defined in an
M-file, but can be defined as an inline function, which will
remove the necessity of quotes(’’).
x0 : an initial guess x 0 of the solution
A,b : a linear inequality constraints Ax ≤ b;tobegiven as [] if not
applied.
Aeq,beq: a linear equality constraints A eq x = b eq ; to be given as [] if not
applied.
l,u : lower/upper bound vectors such that l ≤ x ≤ u; to be given as []
if not applied, set l(i) = -inf/u(i) = inf if x(i) is not
bounded below/above.
’nlcon’: a nonlinear constraint function defined in an M-file, supposed to
return the two output arguments for a given x; the first one being
the LHS (vector) of inequality constraints c(x) ≤ 0 and the
second one being the LHS (vector) of equality constraints
c eq (x) = 0; to be given as [] if not applied.
options: used for setting the display parameter, the tolerances for x o and
f(x o ), and so on; to be given as [] if not applied. For details,
type ‘help optimset’ into the MATLAB command window.
p1,p2,.: the problem-dependent parameters to be passed to the objective
function f(x) and the nonlinear constraint functions c(x), c eq (x).
ž Output Arguments
xo : the minimum point (x o ) reached in the permissible region
satisfying the constraints
fo : the minimized function value f(x o )
%nm732_1 to solve a constrained optimization problem by fmincon()
clear, clf
ftn=’((x(1) + 1.5)^2 + 5*(x(2) - 1.7)^2)*((x(1)-1.4)^2 + .6*(x(2)-.5)^2)’;
f722o = inline(ftn,’x’);
x0 = [0 0.5] %initial guess
A = []; B = []; Aeq = []; Beq = []; %no linear constraints
l = -inf*ones(size(x0)); u = inf*ones(size(x0)); % no lower/upperbound
options = optimset(’LargeScale’,’off’); %just [] is OK.
[xo_con,fo_con] = fmincon(f722o,x0,A,B,Aeq,Beq,l,u,’f722c’,options)
[co,ceqo] = f722c(xo_con) % to see how constraints are.