Numerical Optimization in Matlab
Numerical Optimization in Matlab
Andrii Parkhomenko
Spring 2017
Case 1:
max f (x) = 0.5x − 0.02x 2
x
Case 2:
1
max f (x) = 0.5 ln x − 0.02x 2 + 5
x (1 + x) 3
Can’t solve analytically ⇒ need to use numerical methods
Example 1:
1
max f (x) = 0.5 ln x − 0.02x 2 + 5
x (1 + x) 3
0.6
0.4
0.2
−0.2
f(x)
−0.4
−0.6
−0.8
−1
−1.2
−1.4
0 1 2 3 4 5
x
Example 1:
1
max f (x) = 0.5 ln x − 0.02x 2 + 5
x (1 + x) 3
Step 2. Function
function y = objfun(x)
y = 0.5*log(x) - 0.02*x^2 + (1+x)^(-5/3);
y = -y;
end
xk+1 = xk + αk pk
1 Compute direction pk
pk = −Bk−1 ∇fk
Bk sk sk0 Bk yk yk0
Bk+1 = Bk − +
sk0 Bk sk yk0 sk
where sk ≡ xk+1 − xk and yk ≡ fk+1 − fk
min f (xk + αk pk )
αk
Introduce options:
options = optimset(’Opt1’,Opt1Val,’Opt2’,Opt2Val,...);
x = fminunc(@objfun,x0, options)
Caution:
Objective function must be continuous
Local minima and flat regions are big issues
1.5
0.5
f(x)
−0.5
−1
−1.5
0 1 2 3 4 5
x
0.6
0.4
0.2
−0.2
f(x)
−0.4
−0.6
−0.8
−1
−1.2
−1.4
0 1 2 3 4 5
x
1.5
1
f(x)
0.5
−0.5
−1
0 1 2 3 4 5
x
Example 1:
1
max f (x) = 0.5 ln x − 0.02x 2 + 5 s.t. x ≤ a
x (1 + x) 3
0.6
0.4
0.2
−0.2
f(x)
−0.4
−0.6
−0.8
−1
−1.2
−1.4
0 1 2 3 4 5
x
Andrii Parkhomenko (UAB & Barcelona GSE) Numerical Optimization in MATLAB 15 / 24
fmincon
Example 1:
1
max f (x) = 0.5 ln x − 0.02x 2 + 5
x (1 + x) 3
0.6
0.4
0.2
−0.2
f(x)
−0.4
−0.6
−0.8
−1
−1.2
−1.4
0 1 2 3 4 5
x
1.5
0.5
f(x)
−0.5
−1
−1.5
0 1 2 3 4 5
x
0.6
0.4
0.2
−0.2
f(x)
−0.4
−0.6
−0.8
−1
−1.2
−1.4
0 1 2 3 4 5
x
1.5
1
f(x)
0.5
−0.5
−1
0 1 2 3 4 5
x
5
f(x)
0
0 5 10 15 20
x