0% found this document useful (0 votes)
50 views5 pages

Tugas Fisika Komputasi Optimization

The document provides instructions for three optimization problems: 1) Use golden section search to find the maximum value of a function f(x) between 0 and 2 over 3 iterations. 2) Use parabolic interpolation to find the maximum value of f(x) between 0, 1, and 2 over 3 iterations. 3) Use the Newton's method to find the root of a function starting from 2 over 3 iterations.

Uploaded by

Yesriely
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views5 pages

Tugas Fisika Komputasi Optimization

The document provides instructions for three optimization problems: 1) Use golden section search to find the maximum value of a function f(x) between 0 and 2 over 3 iterations. 2) Use parabolic interpolation to find the maximum value of f(x) between 0, 1, and 2 over 3 iterations. 3) Use the Newton's method to find the root of a function starting from 2 over 3 iterations.

Uploaded by

Yesriely
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

TUGAS FISIKA KOMPUTASI

(16 April 2020)


Materi : Optimization
Nama : Yesriely
Nim : H021181302

Selesaikan untuk nilai x yang memaksimalkan f (x) dalam Prob. 13.2 menggunakan golden
section. Gunakan tebakan awal xl = 0 dan xu = 2 dan lakukan tiga iterasi.

function[x, fx]=goldenSection(xl, xu, maxit, es, option)


fxl=f(xl);
fxu=f(xu);
R=(sqrt(5)-1)/2;
ifoption=="max"
opt=1;
end
ifoption=="min"
opt=0;
end
fori=1:maxit
d=R*(xu-xl);
x1=xl+d;
x2=xu-d;
fx1=f(x1);
fx2=f(x2);
fprintf("%d %g %g %g %g %g %g %g %g %g\n",i,xl,fxl,x2,fx2,x1,fx1,xu,fxu,d);
e=max((1-R)*(xu-xl)/x1,(1-R)*(xu-xl)/x2);
ifabs(e)<es
break
end
test=(fx1>fx2);
ifopt==test
xl=x2;
fxl=fx2;
else
xu=x1;
fxu=fx1;
end
end
test=(fx1>fx2);
ifopt==test
x=x1;
fx=fx1;
else
x=x2;
fx=fx2;
end
end
Output:
Ulangi Prob. 13.3, kecuali gunakan interpolasi parabola dengan cara yang sama seperti
Contoh 13.2. Gunakan tebakan awal x0 = 0, x1 = 1, dan x2 = 2 dan lakukan tiga iterasi.

function[x, fx]=parabolic(x0, x2, maxit, es)


x1=(x0+x2)/2;
f0=f(x0);f1=f(x1);f2=f(x2);
iff1<f0&&f1<f2
x="error";
fx="error";
end
fori=1:maxit
x3=(f0*(x1^2-x2^2)+f1*(x2^2-x0^2)+f2*(x0^2-x1^2))/(2*f0*(x1-x2)+2*f1*(x2-x0)+2*f2*(x0-x1));
f3=f(x3);
fprintf("%d %g %g %g %g %g %g %g %g\n",i,x0,f0,x1,f1,x2,f2,x3,f3);
iff3>f1
ifx3<x1
x2=x1;
f2=f1;
else
x0=x1;
f0=f1;
end
x1=x3;
f1=f3;
else
ifx3<x1
x0=x3;
f0=f3;
else
x2=x3;
f2=f3;
end
end
ifabs((x0-x2)/x1)<es
break
end
end
x=x1;
fx=f1;
end

Output:
Ulangi Prob. 13.3 tetapi gunakan metode Newton. Gunakan tebakan awal x0 = 2 dan
lakukan tiga iterasi.

functiony=f(x)
x=2*sin(x)-x^2/10;
end

function[x, fx]=Newton(x0, maxit, es)


fori=1:maxit
xold=x0;
x0=x0-df(x0)/ddf(x0);
e=abs((x0-xold)/x0);
fprintf("%d %g %g %g %g\n",i,x0,df(x0),ddf(x0),e);
ife<esbreakend
end
x=x0;
fx=f(x);
end

functiony=f(x)
y=2*sin(x)-x^2/10;
end

functiony=df(x)
y=2*cos(x)-x/5;
end

functiony=ddf(x)
y=-2*sin(x)-0.2;
end

Output:
Gunakan metode berikut untuk menemukan maksimum
f(x) = 4x - 1.8x2 + 1.2x3 - 0.3x4

You might also like