6 80
5
60
4
3 40
2
20
1
0
0
-40
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
x
Fungsi unimodal kontinyus
f(x)
Contoh fungsi single var
Dalam suatu pabrik kimia, ongkos dari pemipaan, fitting dan pumping adalah
ongkos investasi yang memegang peran penting. Perhatikan desain suatu
pipa dengan panjang L yang harus membawa cairan (fluid) dengan rate Q
gpm. Pemilihan diameter diameter pipa yang ekonomis D (dalam inchi)
didasarkan pada minimasi biaya tahunan dari pipa, pompa dan pemompaan.
Misalkan ongkos tahunan dari dari suatu jaringan pipa dengan pipa baja
carbon standard dan pompa centrifugal dengan digerakkan suatu motor dapat
dinyatakan dengan persamaan fungsi berikut
diameter
Prinsip-prinsip dasar Metoda kalkulus
Single-variable optimization
f(x)
A 1 , A 2 , A 3 : Relative maxima
.
A2 A 2 : Global maximum
B 1 , B 2 : Relative minima
B 1 : Global minimum
.
A1
.
A3
.
B2
.
B1
x
a b
Gambar 2.1 titik Local and global optimum pada fungsi multimodal 6
Single-variable optimization
f(x)
global maximum
inflection point
local minimum
global minimum
7
Single-variable optimization
Kriteria optimalitas
f '(x*) 0 (2.1)
8
Contoh saddle point f(x)=x3
80
60
-20
-40
-60
-80
0
x
Single-variable optimization
(n) d n f (x)
dimana f (x) (2.3)
dx n
Jika n ganjil maka x* adalah saddle point atau inflection
point.
Jika n genap, maka x* adalah local optimum. Yaitu:
(n)
Jika f (x*) 0 , maka x* adalah a local minimum.
Jika f (n) (x*) 0 maka x* adalah a local maximum. 10
Catatan
Syarat perlu dan syarat cukup, mensyaratkan
bahwa fungsi yang dievaluasi harus twice
differentiable.
6 165 4 5
f(x) 5 x 36 x x 60 x 3 36
2
df
30 x 5 180 x 4 330 x 3 180 x 2 30 x 2 ( x 1)( x 2)( x 3)
dx
Turunan pertama ini bernilai 0 pada x=0, 1, 2, 3.
Sehingga titik-titik ini diklasifikasikan sebagai titik stasioner.
d2 f 4 3 2
2
150 x 720 x 990 x 360 x
dx
Pada x=0, didapat
d3 f 3 2
3
600 x 2160 x 1980 x 360 360
dx
Sehingga x=0 adalah titik infleksi.
lanjutan
x f(x) d2f/dx2
0 36 0
1 27.5 60
2 44 -120
3 -4.5 540
f(x1)+(1-)f(x2) f(x2)
f(x)
f(x1)
f[x1+(1-)x2]
x1 x1+(1-)x2 x2
f(x)
f(x0)
f(x0)+ f(x0)(x-x0)
x0 x
df
x x* 3 x 2 6 x 9 0 x* 3,1
dx
40
f(x) 25
20
15
10
5
-2 -1 0 1 2 3 4
x x*
The MATLAB Code contoh desain
pipa
d=linspace(0.25,6);
l=1000;q=20;
for i=1:100
hp=4.4e-8*(l*q^3)/d(i)^5
+ 1.92e-9*(l*q^2.68)
/(d(i)^4.68);
cost
f(i)=0.45*l+0.245*l*d(i)^
1.5+3.25*hp^0.5+61.6*h
p^0.925+102;
end
diameter
2. Example- Continued
Carilah nilai minimum dari f(x)=3x2+12/x-5
df/dx=6x-12/x2=0
Solutions Methods (1) Analytical
Approach
Problem:
min f x
x
s.t. a x b
Algorithm
Step 1: Set df/dx=0 and solve all stationary points.
Step 2: Select all stationary point x1, x2,…,xN in [a,b].
Step 3: Compare function values f(x1), f(x2),…,f(xN)
and find global minimum.
Example: Polynomial Problem
Example: max f ( x) x 3 3x 2 9 x 10
In the interval of [-2,4].
df
x x* 3 x 2 6 x 9 0 x* 3,1
dx
40
f(x) 25
20
15
10
5
-2 -1 0 1 2 3 4
x x*
Contoh Inventory Control
(Ravindran example 2.4)
Inventory quantity each time =Q units
Set up cost or ordering cost =$K
Acquisition cost =$C/unit
Storing cost per unit =$h/year
Demand (constant)= units/time unit, this
implies ordering period =T=Q/
Question: What is optimum ordering amount
Q?
Solution Cost per ordering cycle K CQ QhT / 2
Inventroy
control
Time
K h 2K Q* 2K
f ' Q Q* 0 or T *
Q2 2 h h
Problems
Cost function harus dinyatakan secara
eksplisit
Turunan dari fungsi ongkos harus dituliskan
secara eksplisit
Selesaiakn persamaan turunan
Dalam banyak kasus persamaan turunan
tidak diselesaikan secara analitik tetapi
secara numerik, misalnya menggunakan
metoda Newton’s yang lebih mudah
dibanding menggunakan cara analitik
Problems - Continued
x*
a
b
Location of global
minimum
Metoda Search single variable
Min f(x), st a ≤ x ≤ b
Masalah yang sering kita hadapi
Untuk sembarang titik x mungkin f’(x) tidak eksis
jadi kita tidak bisa menggunakan metoda kalkulus. Perlu suatu
metoda yang tidak memerlukan f’(x).
f’(x)=0, sulit dicari solusinya
Untuk fungsi tertentu, kadang-kadang f’(x) = 0 tidak mudah
dicari solusinya. Apalagi kalau f’(x) mempunyai pangkat
pecahan. Untuk itu perlu dicari cara bagaimana menemukan
titik optimal yang tidak memakai turunan.
Metodanya antara lain: Interval halving, Golden section
Interval halving (tidak memakai gradien)
f2
f1
fm
x
a x1 xm x2 b
Situasi dimana f(x1)<f(x2)
Interval Halving
f(x) Minimum terletak antara (x1,b)
f1
f2
fm
x
a x1 xm x2 b
Situasi dimana f(x1)>f(x2)
Algoritma Interval halving
Ulangi sampai kriteria penghentian dipenuhi
L=b-a;
xm=(a+b)/2;
x1=a+L/4;
x2=b-L/4;
Hitung f(x1), f(x2) dan f(xm)
Jika f(x1)<= f(xm)
maka eliminasi (xm,b) dan set b=xm;
jika f(x2)<= f(xm)
maka eliminasi (a,xm) dan set a=xm;
jika f(xm) ≤ f(x1) dan f(xm) ≤ f(x2)
maka eliminasi (a,x1) dan set a=x1;
eliminasi (x2,b) dan set b=x2;
Selesai
contoh
Carilah minimum dari f(x)=(100-x)2,
60 ≤x ≤ 150, dengan interval halving
a=60, b=150, L=150-60=90
xm=0.5(60+150)=105
x1=60+(1/4) 90=82.5, x2=150-(1/4)90=127.5
f(x1)=(100-82.5)2=306.5, f(xm)=25
f(x2)=(100-127.5)2=756.25, bandingkan
Karena f(x1)>f(xm) dan f(x2)>f(xm) maka
a=82.5, b=127.5 xm=105; dst
Golden Section
Golden section search, salah satu metoda untuk
mencari titik optimal pada single variabel jika
diketahui interval awal b-a
f(x) Golden section ratio:
1 5
τ 0,61803...
2
(1-τ)L 0 τL 0 1-τ
τL 0 (1-τ)L 0
a x3 x1 x2 b x τ
τ2L 0
L0
35
Ide dasar
(untuk kasus minimasi fungsi)
Kita ambil 2 titik x1 < x2 dalam L=[a,b], bandingkan f(x1) dan f(x2),
jika
kasus 1
Dalam kasus minimasi jika f(x1) < f(x2) maka kita eliminasi area
x > x2 sehingga x*[a,x2].
kasus 2
f(x1) = f(x2) maka eliminasi area x < x1 dan x > x2 , sehingga
x*[x1,x2].
kasus 3
f(x1) > f(x2) maka eliminasi area x < x1 sehingga x*[x1,b]
L1
a x1 x2 b
L2
L3 L4
b x2 x1 a
Dalam hal ini berlaku prinsip L1=L2+L3
L2=L3+L4 dan
jika L2 = rL1 dan L3= rL2 = r2L1 ,
dimasukkan ke dalam L1=L2+L3, maka akan
didapat
L1= rL1+ r2L1 r+r2-1=0
Dengan menyelesaikan persamaan kuadrat
ini ditemukan r=0.618.
Golden section search
L0 = b – a
x1 a (1 )L 0
x 2 a L 0
jika f(x1) < f(x2), maka x* terletak dalam interval (a, x2).
jika f(x1) ≥ f(x2), maka x terletak dalam interval (x1, b).
n L N L 0
N
n τ
Convergence criteria:
(i) N N max
(ii) L N ε1
(iii)
f x N 1 f x N ε2 40
Algoritma: Golden-Search
Tentukan a, b
Lakukan sampai stopping criteria tercapai (jumlah
iterasi)
r=0.618;
x1= a+(1-r)*(b-a);
x2= a-r*(b-a);
jika f(x1) > f(x2), a=x1;
jika f(x1)=f(x2), a=x1,b=x2;
Untuk lainnya (f(x1)<f(x2))
b=x2;
end
Contoh f(x)=(100-x)2 ,
60<=x<=150
Gunakan a=60, b=150, r=0.618
x1=60+(1-0.618)(150-60)=
x2=60+0.618(90)=
Bandingkan f(x1) dan f(x2)
PR
buku Eng Optimization (Ravindran) exercise
2.1,2.2,2.3,2.4,2.6,2.7
Tulis tangan
Jika 2 orang sama, nilai dibagi 2.
MATLAB CODING – The Golden
Search
function al_opt=goldsec(op2_func,tol,x0,d)
b=1;a=0;l=b-a;
tau=0.61803;
x2=a+tau*l;
x1=a+(1-tau)*l;
while l>tol
xx1=x0+x1*d;xx2=x0+x2*d;
y1=feval(op2_func,xx1);y2=feval(op2_func,xx2);
jika(y1>=y2) a=x1;x1=x2;l=b-a;x2=a+tau*l;
else
b=x2;x2=x1;l=b-a;x1=a+(1-tau)*l;
end
end
al_opt=b;
Example : The Piping Problem
x0=0.25;d=6-0.25;tol=1.e-6;
al_opt=goldsec('obj_piping',tol,x0,d);
D=x0+al_opt*d;
function y=obj_piping(D)
%D(in)
L=1000;%ft
Q=20;%gpm
hp=4.4e-8*(L*Q^3)/(D^5)+1.92e-9*(L*Q^2.68)/(D^4.68);
y=0.45*L+0.245*L*D^1.5+3.25*(hp)^0.5+61.6*(hp)^0.925+102;
al_opt =0.1000
D =0.8250
fun_call =29
Remarks
Setiap tahap, hanya satu function evaluation
yang diperlukan.
panjang interval pencarian mengecil dengan
r pada tiap iterasi L L 0.618...
N 1
N
Newton – Raphson method
f xk
Series of trial points: xk 1 xk (5.23)
f x k
f'(x)
x1 x*
x3 x2 x
Convergence criteria:
(i)
f x k 1 ε1
(ii) xk 1 xk ε2
(iii)
f x k 1 f x k ε3
48
Newton – Raphson method
f'(x)
x* x0 x1 x2 x3 x
49
The Importance of One-dimensional Problem
- The Iterative Optimization Procedure
Optimization is basically performed in a fashion of
iterative optimization. We give an initial point x0,
and a direction s, and then perform the following
line search:
x1 x 0 * s
min f 4 1 17 8 2
2 2
df
8 2 0
d
4 QED
The new point is at
(0,-1) as shown
Solution Methods (2) – Numerical
Approaches: (i) Numerical Solution to Optimality
Condition
Example: Determine the
minimum of
f(x)=(10x3+3x2+x+5)2
fx = -1.6983e-006
iter = 53
x0 = -0.9073
A Numerical Differentiation Approach
Problem: Find df/dx at a point xk
Approach:
Define xk
Find f(xk)
Find f(xk+ xk )
Approximate df/dx=[(f(xk+ xk )- f(xk))/ xk ]
A Numerical Differentiation
Approach-MATLAB code
x0=10;fx=100;iter=0;ff=[];xx=[];dx=0.001;
while abs(fx)>1.e-5
fx=2*(10*x0^3+3*x0^2+5)*(30*x0^2+6*x0+1);
ff=[ff;fx];
xp=x0+dx;
ffp=2*(10*xp^3+3*xp^2+5)*(30*xp^2+6*xp+1);
fxp=(ffp-fx)/dx;
x0=x0-fx/fxp;
xx=[xx;x0];
iter=iter+1;
end
fx = -4.4285e-008
iter = 38
x0 = -0.9073
Remarks (Numerical Solution to
Optimality Condition)
Difficult to formulate the optimality condition
Difficult to solve (multi-solutions, complex
number solutions)
Derivative may be very difficult to solve
numerically
Function calls are not saved in most cases
Algorithm ab
xm
Step 1: Let , L= b-a, 2find f(xm)
Step 2: Set x1=a+L/4, x2=b-L/4.
Step 3: Find f(x1), if f(x1)<f(xm), then bxm,
go to step 1.
if f(x1)>f(xm), continue
Step 4: Find f(x2)
If f(x2)<f(xm), then axm, go to step 1.
If f(x2)>f(xm), then ax1, bx2, go to step 1.
Example:y=(10*x^3+3*x^2+x+5)^2;
a=-3;b=3;l=b-a;xm=(a+b)/2;x1=(a+xm)/2;x2=(xm+b)/2; fm=inter_hal_obj(xm);
iter=1;
while l>1.e-8
f1=inter_hal_obj(x1);
if f1<=fm
b=xm;
else
f2=inter_hal_obj(x2);
if f2<=fm
a=xm;
else
a=x1;
b=x2;
end
end
xm=(a+b)/2;x1=(a+xm)/2;x2=(xm+b)/2; fm=inter_hal_obj(xm);
l=b-a;
iter=iter+1;
end
b =-0.8599
iter = 31
fun_call =82
Remarks
At each stage of the algorithm, exactly half
of the search is deleted.
At most two function evaluations are
necessary at each iteration.
After n iterations, the initial search interval
n
will be reduced to 1
2
According to Krefer, the three point search
is most efficient among all equal-interval
searches.
Remarks - Continued
LN
Define , N = number of experiments, or
FR
L1
function evaluations.
0.5 N / 2 for interval halving
FR N 1
0.618 for golden search
Let E = FR(N)
2 ln E
N for interval halving
ln 0.5
ln E
N 1 for gold search
ln 0.618
I.H. 7 9 14 20
G.S. 6 8 11 16
Solution Methods (2) – Numerical Approaches
(iii) Polynomial Approximation Methods –
Powell’s Method
Powell’s method is to approximate an
objective function by a quadratic function
such as f(x)=ax2+bx+c, then it can be shown
the optimum is located at x*=-b/2a.
Given the above equation we need to do
three experiments (function calls) to fit a
quadratic function, let the three experiments
(function calls) located at: f(x1), f(x2), f(x3) and
let’s rewrite the quadratic equation based on
the new notation: qx a0 a1 x x1 a 2 x x1 x x 2
Powell’s Method- Continued
The parameters in the previous slide can be
found using three experiments:
f x1 f1 a0
f 2 f1
f x2 f 2 a0 a1 x2 x1 a1
x2 x1
11 f 3 f1 f 2 f1
f x3 f 3 a0 a1 x3 x1 a2 x3 x1 x3 x2 a2
x3 x2 x3 x1 x2 x1
al_opt = 0.1000
D =0.8250
fun_call =61
Comparison – Interval_halving
(tol=1.e-6)
l=
6.8545e-007
b=
0.8250
a=
0.8250
iter =
24
fun_call =
63