Solving Optimization Problems Using The Matlab Opt
Solving Optimization Problems Using The Matlab Opt
discussions, stats, and author profiles for this publication at: https://www.researchgate.net/publication/255586170
Article
CITATIONS READS
11 10,887
2 authors, including:
Abebe Geletu
Technische Universitt Ilmenau
21 PUBLICATIONS 89 CITATIONS
SEE PROFILE
Some of the authors of this publication are also working on these related projects:
Optimization and Robust Operation of Complex Systems under Uncertainty and Stochastic Optimization
View project
All content following this page was uploaded by Abebe Geletu on 10 July 2014.
The user has requested enhancement of the downloaded file. All in-text references underlined in blue are added to the original document
and are linked to publications on ResearchGate, letting you access and read them immediately.
Solving Optimization Problems using the Matlab Optimization
Toolbox - a Tutorial
1
Chapter 1
Introduction to Mathematical
Programming
The function f : Rn R is called the objective function and the set M Rn is the feasible set of (O).
Based on the description of the function f and the feasible set M , the problem (O) can be classified
as linear, quadratic, non-linear, semi-infinite, semi-definite, multiple-objective, discrete optimization
problem etc1 .
c x min (max)
s.t.
Ax = a (LO)
Bx b
lb x ub;
Under linear programming problems are such practical problems like: linear discrete Chebychev ap-
proximation problems, transportation problems, network flow problems,etc.
1
The terminology mathematical programming is being currently contested and many demand that problems of the form
(O) be always called mathematical optimization problems. Here, we use both terms alternatively.
2
3
Quadratic Programming
1 T
2 x Qx + q x min
s.t.
Ax = a
(QP)
Bx b
x u
x v
Here the objective function f (x) = 12x Qx + q x is a quadratic function, while the feasible set
M = {x Rn | Ax = a, Bx b, u x v} is defined using linear functions.
One of the well known practical models of quadratic optimization problems is the least squares ap-
proximation problem; which has applications in almost all fields of science.
where, we assume that all the function are smooth, i.e. the functions
f, gl : U R l = 1, 2, . . . , m + p
are sufficiently many times differentiable on the open subset U of Rn . The feasible set of (NLP) is
given by
M = {x Rn | gi (x) = 0, i = 1, 2, . . . , m; gj (x) 0, j = m + 1, m + 2, . . . , m + p} .
Problems of the form (NLP) arise frequently in the numerical solution of control problems, non-linear
approximation, engineering design, finance and economics, signal processing, etc.
4
Semi-infinite Programming
f (x) min
s.t.
G(x, y) 0, y Y ;
hi (x) = 0, i = 1, . . . , p; (SIP)
gj (x) 0, j = 1, . . . , q;
x Rn ;
Y Rm .
Y = {y Rm | uk (y) = 0, k = 1, . . . , s1 ; vl (y) 0, l = 1, . . . , s2 }
The problem (SIP) is called semi-infinite, since its an optimization problem with finite number of vari-
ables (i.e. x Rn ) and infinite number of constraints (i.e. G(x, y) 0, y Y ).
One of the well known practical models of (SIP) is the continuous Chebychev approximation problem.
This approximation problem can be used for the approximation of functions by polynomials, in filter
design for digital signal processing, spline approximation of robot trajectory
Multiple-Objective Optimization
A multiple objective Optimization problem has a general form
where the functions fk : Rn R, k = 1, . . . , m are smooth and the feasible set M is defined in terms of
linear or non-linear functions. Sometimes, this problem is also alternatively called multiple-criteria,
vector optimization, goal attainment or multi-decision analysis problem. It is an optimization
problem with more than one objective function (each such objective is a criteria). In this sense,
(LO),(QP)(NLO) and (SIP) are single objective (criteria) optimization problems. If there are only two
objective functions in (MO), then (MO) is commonly called to be a bi-criteria optimization problem.
Furthermore, if each of the functions f1 , . . . , fm are linear and M is defined using linear functions,
then (MO) will be a linear multiple-criteria optimization problem; otherwise, it is non-linear.
For instance, in a financial application we may need, to maximize revenue and minimize risk at the
same time, constrained upon the amount of our investment. Several engineering design problems can
also be modeled into (MO). Practical problems like autonomous vehicle control, optimal truss design,
antenna array design, etc are very few examples of (MO).
In real life we may have several objectives to arrive at. But, unfortunately, we cannot satisfy all
our objectives optimally at the same time. So we have to find a compromising solution among all
our objectives. Such is the nature of multiple objective optimization. Thus, the minimization (or
5
maximization) of several objective functions can not be done in the usual sense. Hence, one speaks
of so-called efficient points as solutions of the problem. Using special constructions involving the
objectives, the problem (MO) can be reduced to a problem with a single objective function.
c x min
s.t.
Ax a (LP)
Bx = b
lb x ub;
MATLAB: The program linprog.m is used for the minimization of problems of the form (LP).
Once you have defined the matrices A, B, and the vectors c,a,b,lb and ub, then you can call linprog.m
to solve the problem. The general form of calling linprog.m is:
[x,fval,exitflag,output,lambda]=linprog(f,A,a,B,b,lb,ub,x0,options)
Input arguments:
Output arguments:
x optimal solution
fval optimal value of the objective function
exitflag tells whether the algorithm converged or not, exitflag > 0 means convergence
output a struct for number of iterations, algorithm used and PCG iterations(when LargeScale=on)
lambda a struct containing lagrange multipliers corresponding to the constraints.
6
7
Setting Options
The input argument options is a structure, which contains several parameters that you can use with
a given Matlab optimization routine.
For instance, to see the type of parameters you can use with the linprog.m routine use
>>optimset(linprog)
Then Matlab displays the fileds of the structure options. Accordingly, before calling linprog.m you
can set your preferred parameters in the options for linprog.m using the optimset command as:
>>options=optimset(ParameterName1,value1,ParameterName2,value2,...)
where ParameterName1,ParameterName2,... are those you get displayed when you use
optimset(linprog). And value1, value2,... are their corresponding values.
The following are parameters and their corresponding values which are frequently used with linprog.m:
a simplex algorithm;
an active-set algorithm;
The simplex and active-set algorithms are usually used to solve medium-scale linear programming
problems. If any one of these algorithms fail to solve a linear programming problem, then the problem
at hand is a large scale problem. Moreover, a linear programming problem with several thousands of
variables along with sparse matrices is considered to be a large-scale problem. However, if coefficient
matrices of your problem have a dense matrix structure, then linprog.m assumes that your problem
is of medium-scale.
By default, the parameter LargeScale is always on. When LargeScale is on, then linprog.m
uses the primal-dual interior point algorithm. However, if you want to set if off so that you can solve
a medium scale problem , then use
>>options=optimset(LargeScale,off)
8
In this case linprog.m uses either the simplex algorithm or the active-set algorithm. (Nevertheless,
recall that the simplex algorithm is itself an active-set strategy).
If you are specifically interested to use the active set algorithm, then you need to set both the param-
eters LargeScale and Simplex, respectively, to off:
>>options=optimset(LargeScale,off,Simplex,off)
Note: Sometimes, even if we specified LargeScale to be off, when a linear programming problem
cannot be solved with a medium scale algorithm, then linprog.m automatically switches to the large
scale algorithm (interior point method).
c x min
s.t.
Ax a (LP)
Bx = b
lb x ub;
e = x lb we get
if we set x
c x
e c lb min
s.t.
Aex a A(lb) (LP)
Bex = b B(lb)
0 e ub lb;
x
Now, by adding slack variables y Rm and s Rn (see below), we can write (LP) as
c x
e c lb min
s.t.
Aex +y = a A(lb)
(LP)
Bex = b B(lb)
x
e +s = ub lb
e 0, y 0, s 0.
x
Thus, using a single matrix for the constraints, we have
c x
e c lb min
s.t.
A Im Omn x
e a A(lb)
B Opm Opn y = b B(lb)
In Onn In s ub lb
e 0, y 0, s 0.
x
9
Since, a constant in the objective does not create a difficulty, we assume w.l.o.g that we have a problem
of the form
c x min
s.t.
(LP)
Ax = a
x 0.
In fact, when you call linprog.m with the original problem (LP), this transformation will be done by
Matlab internally. The aim here is to briefly explain the algorithm used, when you set the LargeScale
parameter to on in the options of linprog.
Now the dual of (LP) is the problem
b w max
s.t.
(LPD )
A w c
w Rm .
b w max
s.t.
(LPD )
A w + s = c
w Rm , s 0 .
Optimality Condition
It is well known that a vector (x , w , s ) is a solution of the primal-dual if and only if it satisfies the
Karush-Kuhn-Tucker (KKT) optimlaity condition. The KKT conditions here can be written as
A w + s = c
Ax = a
xi si = 0, i = 1, . . . , n(Complemetarity conditions)
(x, y) 0.
Primal-dual interior point methods generate iterates (xk , wk , sk ) that satisfy the system (2.1) & (2.2)
so that (2.2) is satisfied strictly; i.e. xk > 0, sk > 0. That is, for each k, (xk , sk ) lies in the interior
of the nonnegative-orthant. Thus the naming of the method as interior point method. Interior point
methods use a variant of the Newton method for the system (2.1) & (2.2).
10
Central Path
Let > 0 be a parameter. The central path is a curve C which is the set of all points (x( ), w( ), s( ))
C that satisfy the parametric system :
A w + s = c,
Ax = b,
xsi = , i = 1, . . . , n
(x, s) > 0.
where is a step length, usually (0, 1], chosen in such a way that (x+ ( ), w+ ( ), s+ ( ) C.
However, practical primal-dual interior point methods use = , where [0, 1] is a constant and
x s
=
n
The term x s is the duality gap between the primal and dual problems. Thus, is the measure of
the (average) duality gap. Note that, in general, 0 and = 0 when x and s are primal and dual
optimal, respectively.
set
(xk+1 , wk+1 , sk+1 ) (xk , wk , sk ) + k (xk , wk , sk )
choosing k [0, 1] so that (xk+1 , sk+1 ) > 0.
The Matlab LargeSclae option of linprog.m uses a predicator-corrector like method of Mehrotra to
guarantee that (xk , sk ) > 0 for each k, k = 1, 2, . . .
Predicator Step: A search direction (a predicator step) dkp = (xk , wk , sk ) is obtained by solving
the non-parameterized system (2.1) & (2.2).
For this problem there are no equality constraints and box constraints, i.e. B=[],b=[],lb=[] and
ub=[]. Moreover,
>>c=[-2,-3]; % linprog solves minimization problems
>>A=[1,2;2,1;0,1];
>>a=[8,10,3];
>>options=optimset(LargeScale,off);
12
c x max
Ax = a
Bx b
Dx d
lb x lu
where
1 2 3 0 0 0 5
1 1 1 1 1 1 10 0 1 2 3 0 0 7
( A| a) = , ( B| b) = ,
5 0 3 0 1 0 15 0 0 1 2 3 0
8
0 0 0 1 2 3 8
2 7 1
0 2 2
3 0 0
0 2 1 5 1 2 3
( D| d) = , lb =
, lu =
,c =
.
0 4 0 2 0 3 7 1 3 4
5 4 5
1 10 6
When there are large matrices, it is convenient to write m files. Thus one possible solution will
be the following:
function LpExa2
A=[1,1,1,1,1,1;5,0,-3,0,1,0]; a=[10,15];
B1=[1,2,3,0,0,0; 0,1,2,3,0,0;... 0,0,1,2,3,0;0,0,0,1,2,3]; b1=[5,7,8,8];b1=b1(:);
D=[3,0,0,0,-2,1;0,4,0,-2,0,3]; d=[5,7]; d=d(:);
lb=[-2,0,-1,-1,-5,1]; ub=[7,2,2,3,4,10];
c=[1,-2,3,-4,5,-6];c=c(:);
B=[-B1;D]; b=[-b1;d];
[xsol,fval,exitflag,output]=linprog(c,A,a,B,b,lb,ub)
fprintf(%s %s \n, Algorithm Used: ,output.algorithm);
disp(=================================);
disp(Press Enter to continue); pause
options=optimset(linprog);
13
options = optimset(options,LargeScale,off,Simplex,on,Display,iter);
[xsol,fval,exitflag]=linprog(c,A,a,B,b,lb,ub,[],options)
fprintf(%s %s \n, Algorithm Used: ,output.algorithm);
fprintf(%s,Reason for termination:)
if (exitflag)
fprintf(%s \n, Convergence.);
else
fprintf(%s \n, No convergence.);
end
Observe that for the problem above the simplex algorithm does not work properly. Hence,
linprog.m uses automatically the interior point method.
Suppose the measurement of a real process over a 24 hours period be given by the following table
with 14 data values:
i 1 2 3 4 5 6 7 8 9 10 11 12 13 14
ti 0 3 7 8 9 10 12 14 16 18 19 20 21 23
ui 3 5 5 4 3 6 7 6 6 11 11 10 8 6
The values ti represent time and ui s are measurements. Assuming there is a mathematical connection
between the variables t and u, we would like to determine the coefficients a, b, c, d, e R of the
function
u(t) = a t4 + b t3 + c t2 + d t + e
so that the value of the function u(ti ) could best approximate the discrete value ui at ti , i = 1, . . . , 14
in the Chebychev sense. Hence, we need to solve the Chebyshev approximation problem
maxi=1,...,14 ui a t4i + b t3i + c t2i + d ti + e min
(CA)
s.t. a, b, c, d, e R
Then it follows that the problem (CA) can be equivalently written as:
(LP ) f min
s.t.
f ui a t4i + b t3i + c t2i + d ti + e f, i {1, . . . , 14}.
Consequently, we have
14
(LP ) f min
s.t.
a t4i + b t3i + c t2i + d ti + e f ui , i {1, . . . , 14}
a t4i + b t3i + c t2i + d ti + e f ui , i {1, . . . , 14}.
function ChebApprox1
%ChebApprox1:
% Solves a discrete Chebychev polynomial
% approximation Problem
t=[0,3,7,8,9,10,12,14,16,18,19,20,21,23];
u=[3,5,5,4,3,6,7,6,6,11,11,10,8,6];
A1=[-t.^4,-t.^3,-t.^2,-t,-ones(14,1),-ones(14,1)];
A2=[t.^4,t.^3,t.^2,t,ones(14,1),-ones(14,1)];
[xsol,fval,exitflag]=linprog(c,A,a);
ut=xsol(1)*(tt.^4)+xsol(2)*(tt.^3)+xsol(3)*(tt.^2)+xsol(4)*tt+...
xsol(5);
plot(tt,ut,-k,LineWidth,2)
Chapter 3
Problem
1 T
2 x Qx + q T x min
s.t.
Ax a
(QP)
Bx = b
lb x lu
x Rn .
where Q Rnn , A Rmn , B l n, a Rm and b Rl .
Matlab: To solve quadratic optimization problem with Matlab you use the quadprog.m function.
[xsol,fval,exitflag,output,lambda] = quadprog(Q,q,A,a,B,b,lb,ub,x0,options)
Input arguments:
Q Hessian of the objective function
q Coefficient vector of the linear part of the objective function
A,[ ] Matrix of inequality constraints, no inequality constraints
a,[ ] right hand side of the inequality constraints, no inequality constraints
B,[ ] Matrix of equality constraints, no equality constraints
b,[ ] right hand side of the equality constraints,no equality constraints
lb,[ ] lb x : lower bounds for x, no lower bounds
ub,[ ] x ub : upper bounds for x, no upper bounds
x0 Startvector for the algorithm, if known, else [ ]
options options are set using the optimset funciton, they determine what algorism to use,etc.
Output arguments:
x optimal solution
fval optimal value of the objective function
exitflag tells whether the algorithm converged or not, exitflag > 0 means convergence
output a struct for number of iterations, algorithm used and PCG iterations(when LargeScale=on)
lambda a struct containing lagrange multipliers corresponding to the constraints.
15
16
There are specific parameter settings that that you can use with the quadprog.m funciton. To see the
options parameter for quadprog.m along with their default values you can use
>>optimset(quadprog)
Then Matlab displays a structure containing the options related with quadprog.m function. Obsever
that, in contrast to linprog.m, the fields
With quadrprog.m you can solve large-scale and a medium-scale quadratic optimization problems. For
instance, to specify that you want to use the medium-scale algorithm:
>>oldOptions=optimset(quadprog);
>>options=optimset(oldOptions,LargeScale,off);
either if there are no equality and inequality constraints; i.e. if there are only lower and upper
bound constraints;
1 T T
2 x Qx + q x min
s.t. (QP)
lb x lu
>>doc quadprog
(b) Large-Scale algorithm: an interior reflective Newton method coupled with a trust region method.
17
f (x) = 12 x Qx + q x min
s.t.
Ax a (QP)
Bx = b
x Rn .
with Q Rnn , A Rmn , B Rln , a Rm and b Rl .
Optimality conditions:
Necressary condition: x is a local (global) solution of (QP) = There are multipliers Rm
+, R
l
such that
x Q + q + A + B = 0
(a Ax) = 0 (KKT2)
0.
(Karush-Kuhn-Tucker Conditions for QP).
Sufficient condition: If the matrix Q is positively semi definite then (KKT2) is sufficient for global
optimality.
Let I := {1, . . . , m} be the index set corresponding to the inequality constraints and for a given feasible
point xk of (QP), define the active index set of inequality constraints by
I(k) = {i {1, . . . , m} | A(i, :)xk = a},
where the Matlab notation A(i, :) represents the i-th row of the matrix A and
A(k) := a matrix whose rows are the rows of matrix A corresponding to I(k).
Hence, A(k)xk = a.
18
Phase -II:
While 1
Step 1: Determine the active index set I xk and the matrix A(k).
Step 2: Solve the system of equations
A(k) k
d =0 (3.1)
B
xk Q + q +
active A(k) + B = 0. (3.2)
iactive
r
:= min{kactive
i
| kactive
i
< 0, i I(k)}
I(k) = I(k) \ {ir }.
m+l
X
(LP(QP ) ) (x) := xn+i min (3.3)
i=1
s.t. (3.4)
xn+1
.. a;
Ax + . (3.5)
xn+m
xn+m+1
..
Bx + . = b. (3.6)
xn+m+l
If (LP(QP ) ) has no solution, then (QP) is infeasible. If (LP(QP ) ) has a solution x1 , then we have
(x1 ) = 0. This problem can be solved using linprog.m.
(N LP ) f (x) min
s.t.
lb x ub,
General assumption:
GA1: There is a feasible point that satisfies the bound constraints strictly, i.e.
lb < ub.
Hence, if
F := {x Rn | lb x ub}
is the feasible set of (NLP), then int(F) = {x Rn | lb < x < ub} is non-empty;
(N LP ) f (x) min
s.t.
x ub 0,
x + lb 0.
Thus, the first order optimality (KKT) conditions at a point x F will be
f (x) + 1 2 = 0 (3.7)
x ub 0 (3.8)
x + lb 0 (3.9)
1 (x u) = 0 (3.10)
2 (x + l) = 0 (3.11)
1 0, 2 0. (3.12)
That is 1 , 2 Rn+ . For the sake of convenience we also use l and u instead of lb and ub, respectively.
Consequently, the KKT condition can be restated according to the position of the point x in F as
follows:
if, for some i, li < xi < ui , then the complementarity conditions imply that (f (x))i = 0;
if, for some i, xi = ui , then using (GA1) we have li < xi , thus (2 )i = 0. Consequently, (f (x))i =
(1 )i (f (x))i 0.
if, for some i, xi = li , then using (GA1) we have xi < ui , thus (1 )i = 0. Consequently, (f (x))i =
(2 )i (f (x))i 0.
Putting all into one equation we find the equivalent (KKT) condition
(f (x))i = 0, if l < xi < ui ; (3.13)
(f (x))i 0, if xi = ui ; (3.14)
(f (x))i 0, if xi = li . (3.15)
Next define the matrix
|v1 (x)|1/2
... |v2 (x)|1/2 . . . ...
... ... ... ...
D(x) := =: diag(|v(x)|1/2 ),
.
..
... ... . . . |vn (x)|1/2
21
Lemma 3.1.1. A feasible point x satisfies the first order optimality conditions (3.13)-(3.15) iff
Therefore, solving the equation D 2 (x)f (x) = 0 we obtain a point that satisfies the (KKT) condition
for (NLP). Let F (x) := D 2 (x)f (x). Given the iterate xk , to find xk+1 = xk + k dk , a search direction
dk to solve the problem F (x) = 0 can be obtained by using the Newton method
where
Hk := 2 f (xk )
Dk := diag(|v(xk )|1/2 )
|v1 |
Jv (xk ) := ... Rnn
|vn |
(b) due to the definition of the vector v(x), the matrix Jv (x) is a diagonal matrix.
Hence, the system (3.18) can be written in the form
Dk2 Hk + diag(f (xk ))Jv (xk ) dk = Dk2 f (xk ).
Dk Hk Dk + Dk1 diag(f (xk ))Jv (xk )Dk Dk1 dk = Dk f (xk )
| {z }
=diag(f (xk ))Jv (xk )
Dk Hk Dk + diag(f (xk ))Jv (xk ) Dk1 dk = Dk f (xk ).
Now define
k := Dk1 xk
x
dk := D1 dk
k
k := Dk Hk Dk + diag(f (xk ))Jv (xk )
B
gk := Dk f (xk ),
22
) is positive definite.
x is a solution of (NLP) g(x ) = 0 and B(x
= D 1 x, the problem (NLP) has been transformed
It follows that, through the affine transformation x
into an unconstrained minimization problem with gradient vector g and Hessian matrix B.b Consequently,
a local quadratic model for the transformed problem can be given by the trust region problem:
1
(QP )T R (s) = sB + gk s min,
ks
2
s.t.
k
s k k .
Furthermore, the system Bk dk = gk can be considered as the first order optimality condition (considering
d as a local optimal point) for the unconstrained problem (QP)T R with kdk k < k .
k
1
sDk [Hk + Dk1 diag(f (xk ))Jv (xk )Dk1 ]Dk s + f (xk ) Dk s min,
2
s.t.
ksk k .
with s = Dk s and
Bk := Hk + Dk1 diag(f (xk ))Jv (xk )Dk1
we obtain the following quadratic problem in terms of the original variables
1
(QP )T RO sBk s + f (xk ) s min,
2
s.t.
kDk1 sk k .
Consequently, given xk the problem (QP)T RO is solved to determine sk so that
xk+1 = xk + k sk ,
for some step length k .
23
x2=u2 b 1
P
1 P 2
b =X
0 k
b 2
P
x1=l1
x1=u1
x2=l2
Step 1: Let ki be the distance from xk to the nearest boundary point along sk :
Step 2: Define the i-th boundary point as: bki = bki1 + (ik i1
k )pk .
i
Step 2: Determine a descent direction sk for f at xk int(F). Then determine the reflective search
path pk () using the algorithm (RP).
Step 2: Solve f (xk + pk ()) min to determine k in such a way that xk + pk (k ) is not a boundary
point of F.
Step 3: xk+1 = xk + pk (k ).
Under additional assumptions, the algorithm (TIR) has a global super-linear and local quadratic con-
vergence properties. For details see the papers of Coleman & Li ([1] - [3]).
Multiple image restoration and enhancement
Soution:
1 2 8
2 0 2 0
Q= ,q = , A = 2 1 , a = 10 , B = [ ], b = [ ], lb = , ub =
0 4 3 0
0 1 3
Matlab Solution
function QpEx1
lb=[0,0]; ub=[inf;inf];
options=optimset(quadprog);
options=optimset(LargeScale,off);
[xsol,fsolve,exitflag,output]=QUADPROG(Q,q,A,a,[],[],lb,ub,[],options);
25
fprintf(%s ,Convergence: )
if exitflag > 0
fprintf(%s \n,Ja!);
disp(Solution obtained:)
xsol
else
fprintf(%s \n,Non convergence!);
end
Soution:
2 1 0 4
1 1 1 6
Q = 1 4 2 , q = 6 , A = ,a = ,
1 1 2 12
0 2 4 12
0
B = [ ], b = [ ], lb = 0 , ub =
0
Matlab Solution
function QpEx2
lb=[0;0;0]; ub=[inf;inf;inf];
options=optimset(quadprog);
options=optimset(LargeScale,off);
[xsol,fsolve,exitflag,output]=QUADPROG(Q,q,A,a,[],[],lb,ub,[],options);
fprintf(%s ,Convergence: )
if exitflag > 0
26
fprintf(%s \n,Ja!);
disp(Solution obtained:)
xsol
else
fprintf(%s \n,Non convergence!);
end
where kp , kf and km denote the variable production cost rates, the fix costs and the variable costs for
the material. Further assume that the price p of a product depends on the number of products x in
some linear relation
pi = ai bi xi , ai , bi > 0, i = 1, 2, ..., n
The profit (x) is given as the difference of the turnover
n
X
T T
T (x) = p (x) x = ai xi bi x2i
i=1
and constraints additional constraints on resources. There are resources Bj , j = 1, . . . , m with con-
sumption amount yj , j = 1, 2, ..., m. Then the yj s and the amount of final products xi have the linear
connection
y = Rx
27
(cj dj yj ) yj , j = 1, 2, ..., m
Ax r
Bx s.
If we want to maximize the profit (or minimize loss) we get the following quadratic problem
1 e
x B + R DR x + (a kp + R c) x kf max
2
s.t.
Bx a
kp x k0 kf
Rx ymin
Rx ymax
Ax r
Bx s
0 < xmin x xmax .
Use hypothetical, but properly chosen, data for A,B,R,a,b,c,d,r,s,xmin,xmax,kp,k0,kf to run the follow-
ing program to solve the above profit maximization problem.
function [xsol,fsolve,exitflag,output]=profit(A,B,R,a,b,c,d,r,s,xmin,xmax,kp,k0,kf)
%[xsol,fsolve,exitflag,output]=profit(A,B,R,a,b,c,d,r,s,xmin,xmax,kp,k0,kf)
%solves a profit maximization prblem
28
Bt=-2*diag(b); D=-2*diag(d);
%%1/2xQx + qx
Q=Bt + R*D*R; q=a-kp+R*c;
A=[diag(b);kp;-R;R;A;-B];
options=optimset(quadprog);
options=optimset(LargeScale,off);
[xsol,fsolve,exitflag,output]=quadprog(-Q,-q,A,a,[],[],lb,ub,[],options);
Bibliography
[1] T. F. Coleman, Y. Li: On the convergence of interior-reflective Newton methods for non-linear
optimization subjecto to bounds. Math. Prog., V. 67, pp. 189-224, 1994.
[2] T. F. Coleman, Y. Li: A reflective Newton method for minimizing a quadratic function subject to
bounds on some of the variables. SIAM Journal on Optimization, Volume 6 , pp. 1040 - 1058,
1996.
[3] T. F. Coleman, Y. Li: An interior trust region approach for nonlinear optimization subject to
bounds. SIAM Journal on Optimization, SIAM Journal on Optimization, V. 6, pp. 418-445, 1996.
29
Chapter 4
Assumptions:
Smooth problem:
f C k, k 1
M open set
Convex problem:
f : M Rn R
M convex set
f convex function
f locally Lipschitzian
f difference of convex functions
M convex:
For all x, y M, [0, 1] :
x + (1 ) y M
f convex:
M convex and for all x, y M, [0, 1] :
f (x + (1 ) y) f (x) + (1 ) f (y)
30
31
f Lipschitzian:
There is a K 0 such that for all x, y M :
|f (x) f (y)|
q K kx yk
kx yk = (x y)T (x y)
Locally Lipschitzian: If, for any x M , there is a ball B (x) around x and a constant K such that f
is Lipschitzian on M B.
M
f has a local minimum at x
= f (
x) = 0, k = 1, 2, ..., n
xk
(1) f (
x) = 0, k = 1, 2, ..., n
xk
2
(2) Hf (x) = 2 f (x) = f (
x)
xj xk nn
is positively definite
M
= f has a strict local minimum at x
Remark: A symmetric Matrix H is positively definite all eigenvalues of H are greater than zero.
MATLAB call:
= eig (H)
computes all eigenvalues of the Matrix H and stores them in the vector .
(1) f (
x) = 0, k = 1, 2, ..., n
xk
2 2
(2) x) = f (
Hf ( x) = f (
x)
xj xk nn
has only nonzero eigenvalues but at least two
with different sign
M
= f has a saddle point at x
32
Descent direction: A vector d is a descent for f at x if the angle between f (x) and d is larger than
180o :
f (x)T d < 0
Hk+1 sk = q k .
To determine a symmetric positive matrix Hk+1 , given that Hk is symmetric positive definite matrix
Hk and satisfies the (QNC1), we must have
0 < sk Hk+1 sk = sk q k .
sk q k > 0 (quasi-Newton condition (QNC2))
Thus, given a symmetric positive definite matrix Hk , at each successive iteration the matrix Hk+1 is
determined using a matrix updating Formula:
(Hk sk )(Hk sk ) q k (q k )
Hk+1 = Hk + k k,
(sk ) Hk sk (q ) s
xk+1 = xk + k dk+1
dk+1 = Hk+1
1
f (xk ).
1
However, in the above formula, the determination of Hk+1 at each step might be computationally
expensive. Hence, dk+1 can also be determined by using
34
for, each k {1, 2, . . . , }, the search direction dk , that is determined using either BFGS or DFP is a
descent direction for f at xk , i.e. f (xk ) dk < 0;
if Hk and Bk are symmetric and positive definite and (sk )q k > 0, then the matrices Hk+1 and
Bk+1 are symmetric and positive definite;
if xk x , then sequence of matrices {Hk } converges to k f (x ) and {Bk } converges to (2 f (x ))1 .
But note that the determination of Hk and Bk does not require the hessian matrix 2 f (xk ).
f (x) min
s.t. x Rn
with f C 2 (Rn ) be given. For a known iterate xk the trust region method determines subsequent
iterates using
xk+1 = xk + dk
where dk is determined by minimizing a local quadratic (approximating) model of f at xk given by
1
qk (x) := f (xk ) + f (xk ) d + d Hk d
2
constrained to a domain , where we expect the resulting direction vector dk could yield a "good"
reduction of f at xk+1 = xk + dk . The constraint set is usually given by
k = {d Rn | kdk k }
and is known as the trust-region1 , where we hope (trust) that the global solution of the problem
1
(QP T )k qk (d) := f (xk ) + f (xk ) d + d 2 f (xk )d min
2
s.t.
d = {d Rn | kdk k }
yields a direction vector dk that brings a "good" reduction of f at xk+1 = xk + dk . Thus, the problem
(QP T )k is widely known as the trust region problem associated with (NLP) at the point xk and k > 0
is the radius of the trust-region.
In the above algorithm the parameter is the overall bound for the trust region radius k and the
expression:
f (xk ) f (xk + dk )
rk =
qk (0) qk (dk )
measures how best the quadratic model approximates the unconstrained problem (NLP). Thus,
aredk := f (xk ) f (xk + dk ) is known as the actual reduction of f at step k + 1; and
predk := qk (0) q(dk ) is the predicted reduction of f achievable through the approximating model
(QPT)k at step k + 1.
Consequently, rk measures the ratio of the actual reduction to the predicted reduction. Hence, at step
k + 1,
if rk 2 , then this step is called a very successful step. Accordingly, the trust-region will be
enlarged; i.e. k+1 k . In particular, a sufficient reduction of f will be achieved through the
model, since
f (xk ) f (xk + dk ) 2 (qk (0) qk (dk )) > 0.
The statements of Thm. 4.6.2 describe the optimality conditions of dk as a solution of the trust-region
sub-problem (QPTR)k . Hence, the choice of dk is based on whether the matrix Hk = 2 f (xk ) is
positive definite or not.
(i) if H is a positive definite matrix and kHk1 gk k < , then for the solution of d of (QP), kdk k =
does note hold; i.e., in this case the solution of (QP) does not lie on the boundary of the feasible set.
Assume that Hk is a positive definite, kHk1 gk < and kdk k = hold at the same time. Hence,
from Thm. 4.6.2(b), we have that
(I + Hk1 )d = Hk1 gk dk d + k dk Hk1 dk = dk Hk1 gk ,
k
dk dk + dk dk dk Hk1 gk
maxEig(Hk )
k
1+ kdk k2 k dk kkHk1 gk k < kdk k = kdk k2 ,
maxEig(Hk )
k
where maxEig(Hk ) is the largest eigenvalue of H. Hence, 1 + maxEig(Hk ) kdk k2 < kdk k2 . But
this is a contradiction, since k 0.
(ii) Conversely, if (QP) has a solution d such that kdk k < , it follows that k = 0 and Hk is positive
definite. Obviously, from Thm. 4.6.2(a), we have k = 0. Consequently, Hk + k I is positive
definite, implies that Hk is positive definite.
The Matlab trust-region algorithm tries to find a search direction dk in a two-dimensional subspace of
Rn . Thus, the trust-region sub-problem has the form:
1
(QP T )k qk (d) := f (xk ) + gk d + d Hk d min
2
s.t.
d = {d Rn | kdk k , d Sk },
Sk = hgk , uk i
such that
u
k Hk uk < 0.
Remark 4.6.4. Considering the case when Hk is not positive definite, we make the following observations.
(i) If the Hk has negative eigenvalues, then let k1 be the smallest negative eigenvalue and wk be the
corresponding eigenvector . Hence, we have
Hk wk = 1 wk wk Hk wk = k1 kwk k2 < 0.
Hk uk = gk .
L
This follows from the fact that Hk is a symmetric matrix and Rn = N (Hk ) R(Hk )2 .
(iia) Otherwise, there is always a non-zero vector uk 6= 0 such that u
k Hk uk 0.
(iii) The advantage of using a direction of negative curvature is to avoid the convergence of the algorithm
to a saddle point or a maximizer of (QPTR)k
A detailed discussion of the algorithms for the solution of the trust-region quadratic sub-problem
(QPT)k are found in the papers [1, 9] in the recent book of Conn et al. [2].
4.6.2 The Trust Sub-Problem under Considered in the Matlab Optimization toolbox
The Matlab routine fminunc.m attempts to determine the search direction dk by solving a trust-region
quadratic sub-problem on a two dimensional sub-space Sk of the following form :
1
(QP T 2)k qk (d) := gk d + d Hk d min
2
s.t.
d = {d Rn | kDdk k , d Sk },
2
L
N (Hk ) R(Hk ) represents the direct-sum of the null- and range -spaces of Hk .
39
The scaling matrix D is usually chosen to guarantee the well-posedness of the problem. For this
problem the optimality condition given in Thm. 4.6.2 can be stated as
(Hk + k D D)dk = gk .
At the same time, the parameter k can be thought of as having a regularizing effect in case of
ill-posedness. However, if we use the variable transformation s = Dd we obtain that
1
(QP T 2)k qk (s) := gk (D1 s) + (D1 s) Hk (D1 s) min
2
s.t.
d = {d Rn | ksk k , D1 s Sk },
where egk := D1 gk and He k := D1 Hk Dk . The approach described in Sec. 4.6.1 can be used to
solve (QPT2)k without posing any theoretical or computational difficulty. For a discussion of problem
(QPT2)k with a general non-singular matrix D see Gay [3].
Input arguments:
Output arguments:
To display the type of options that are available and can be used with the fminunc.m use
>>optimset(fminunc)
Hence, from the list of option parameters displayed, you can easily see that some of them have default
values. However, you can adjust these values depending on the type of problem you want to solve.
However, when you change the default values of some of the parameters, Matlab might adjust other
parameters automatically.
As for quadprog.m there are two types of algorithms that you can use with fminunc.m
40
(i) Medium-scale algorithms: The medium-scale algorithms under fminunc.m are based on the
Quasi-Newton method. This options used to solve problems of smaller dimensions. As usual
this is set using
>>OldOptions=optimset(fminunc);
>>Options=optimset(OldOptions,LargeScale,off);
With medium Scale algorithm you can also decide how the search direction dk be determined by
adjusting the parameter HessUpdate by using one of:
>>Options=optimset(OldOptions,LargeScale,off,HessUpdate,bfgs);
>>Options=optimset(OldOptions,LargeScale,off,HessUpdate,dfp);
>>Options=optimset(OldOptions,LargeScale,off,HessUpdate,steepdesc);
(ii) Large-scale algorithms: By default the LargeScale option parameter of Matlab is always on.
However, you can set it using
>>OldOptions=optimset(fminunc);
>>Options=optimset(OldOptions,LargeScale,on);
When the LargeScale is set on, then fminunc.m solves the given unconstrained problem using
the trust-region method. Usually, the large-scale option of fminunc is used to solve problems
with very large number of variables or with sparse hessian matrices. Such problem, for instance,
might arise from discretized optimal control problems, some inverse-problems in signal process-
ing etc.
However, to use the large-scale algorithm under fminunc.m, the gradient of the objective function
must be provided by the user and the parameter GradObj must be set on using:
>>Options=optimset(OldOptions,LargeScale,on,GradObj,on);
Hence, for the large-scale option, you can define your objective and gradient functions in a single
function m-file :
function [fun,grad]=myFun(x)
fun = ...;
if nargout > 1
grad = ...;
end
However, if you fail to provide the gradient of the objective function, then fminunc uses the
medium-scale algorithm to solve the problem.
Experiment: Write programs to solve the following problem with fminunc.m using both the medium-
and large-scale options and compare the results.
Solution
41
Define the problem in an m-file, including the derivative in case if you want to use the LargeSclae
option.
function [f,g]=fun1(x)
%Objective function for example (a)
%Defines an unconstrained optimization problem to be solved with fminunc
f=x(1)^2+3*x(2)^2+5*x(3)^2;
if nargout > 1
g(1)=2*x(1);
g(2)=6*x(2);
g(3)=10*x(3);
end
Next you can write a Matlab m-file to call fminunc to solve the problem.
function [xopt,fopt,exitflag]=unConstEx1
options=optimset(fminunc);
options.LargeScale=off; options.HessUpdate=bfgs;
[xopt,fopt,exitflag]=fminunc(@fun1,x0,options);
If you decide to use the Large-Scale algorithm on the problem, then you need to simply change
the option parameter LargeScale to on.
function [xopt,fopt,exitflag]=unConstEx1
options=optimset(fminunc);
options.LargeScale=on;
options.Gradobj=on;
[xopt,fopt,exitflag]=fminunc(@fun1,x0,options);
To compare the medium- and large-Scale algorithms on the problem given above you can use
the following m-function
43
function TestFminunc
% Set up shared variables with OUTFUN
history.x = []; history.fval = [];
%searchdir = [];
% call optimization
disp(****************************************)
if i==1
A=history.x;
subplot(2,2,1);
plot([1:m],A(:,1),b,[1:m],A(:,2),r,[1:m],A(:,3),g,LineWidth,1.5);
title(Quasi-Newton iterates);
subplot(2,2,2);
plot([1:n],history.fval,*-r,LineWidth,2);
title(Quasi-Newton - Objective Function Values);
end
if i==2
A=history.x;
subplot(2,2,3);
plot([1:m],A(:,1),b,[1:m],A(:,2),r,[1:m],A(:,3),g,LineWidth,1.5);
title(Trust-region iterates);
subplot(2,2,4);
plot([1:n],history.fval,*-r,LineWidth,2);
title(Trust-region Objective Function Values);
end
end
end disp(****************************************) disp(Iteration
steps of the Matlab trust-region algorithm) i=2; history.x = [];
history.fval = []; options =
optimset(outputfcn,@outfun,display,iter,...
largescale,on,Gradobj,on); xopt = fminunc(@fun1,x0,options);
end
44
If you run TestFminunc.m under Matlab you will get the following graphic output
8
0.5
6
4
0
2
0.5 0
0 5 10 0 5 10
8
0.5
6
4
0
2
0.5 0
1 1.5 2 1 1.5 2
which indicates that the LargeScale option of fminunc applied to the problem in func1.m converges af-
ter a single iterative step. (Compare also the tables that will be displayed when running TestFminunc.m).
Exercises Solve the following unconstrained optimization problems using both the LargeScale
and MediumScale options of the Matlab function fminunc and compare your results. (Hint:
define your functions appropriately and use TestFminunc.m correspondingly.)
(c) (Sine-Valley-Function)
f (x) = 100(x2 sin(x1 ))2 + 0.25x21 min
s.t. x Rn .
x0 = [1, 1]
Hint: For problem (d) the trust-region method performs better. The quasi-Newton method
terminates without convergence, since maximum number of function evaluations
(i.e. options.MaxFunEvals) exceeded 400 (100*numberofvariables). Hence, increase the
value of the parameter options.MaxFunEvals sufficiently and see the results.
45
Thus the Nelder-Mead simplex algorithms search the approximate minimum of a function by
comparing the values of the function on the vertices of a simplex. Accordingly, S k is a simplex
at k-th step of the algorithm with ordered vertices {xk1 , xk2 , . . . , xkn+1 } in such a way that
Hence, xkn+1 is termed the worst vertex, xkn the next worst vertex, etc., for the minimization,
while xk1 is the best vertex. Thus a new simplex S k+1 will be determined by dropping vertices
which yield larger function values and including new vertices which yield reduced function
values, but all the time keeping the number of vertices n + 1 (1 plus problem dimension).
This is achieved through reflection, expansion, contraction or shrinking of the simplex S k . In
each step it is expected that S k 6= S k+1 and the the resulting simplices remain non-degenerate.
Step 0: Start with a non-degenerate simplex S 0 with vertices {x01 , x02 , . . . , x0n+1 }. Choose the
constants
> 0, > 1 ( > ), 0 < < 1, and 0 < < 1
known as reflection, expansion, contraction and shrinkage parameters, respectively.
While (1)
Step 1: Set k k + 1 and label the vertices of the simplex S k so that xk1 , xk2 , . . . , xkn+1
according to
f (xk1 ) f (xk2 ) . . . f (xkn+1 ).
Step 2: Reflect
46
Compute f (xkr ).
If f (xk1 ) f (xkr ) < f (xkn ), then accept xkr and reject xkn+1 and GOTO Step 1.
Otherwise Goto Step 3.
Step 3: Expand
(a) If f (xkr ) < f (xk1 ), then calculate the expansion point xke :
Compute f (xke ).
If f (xke ) < f (xkr ), then accept xke and reject xkn+1 and GOTO Step 1.
Else accept xkr and reject xkn+1 and GOTO Step 1.
(b) Otherwise Go to Step 4.
Step 4: Contract
If f (xkr ) f (xkn ), then perform a contraction between xk and the better of xkn+1 and
xkr :
(a) Outside Contraction: If f (xkn ) f (xkr ) < f (xkn+1 ) (i.e. xkr is better than xkn+1 ),
then perform outside contraction, i.e. calculate
xkc = xk + (xkr xk )
If f (xkcc ) < f (xkn+1 ), then accept xkcc and reject xkn+1 and GOTO Step 1.
Otherwise GOTO Step 5. (perform shrink)
Step 5: Shrink
Define n new points
vi = x1 + (xki x1 ), i = 2, . . . , n + 1
END
Unfortunately, to date, there is no concrete convergence property that has been proved of
the original Nelder-Mead algorithm. The algorithm might even converge to a non-stationary
point of the objective function (see Mickinnon[7] for an example). However, in general, it
has been tested to provide rapid reduction in function values and successful implementations
of the algorithm usually terminate with bounded level sets that contain possible minimum
points. Recently, there are several attempts to modify the Nelder-Mead algorithm to come
up with convergent variants. Among these: the fortified-descent simplical search method (
Tseng [12]) and a multidimensional search algorithm (Torczon [11]) are two of the most
successful ones. See Kelley [5] for a Matlab implementation of the multidimensional search
algorithm of Torczon.
Bibliography
48