Nama Asisten :
Oleh :
LABORATORIUM MATEMATIKA
JURUSAN MATEMATIKA
FAKULTAS MATEMATIKA DAN ILMU PENGETAHUAN ALAM
UNIVERSITAS BRAWIJAYA
MALANG
2018
BAB I
PENDAHULUAN
SOURCE CODE
clc;
clear all;
syms x;
fprintf('Penyelesaian nomor 1 \ndengan menggunakan
Metode Golden Search Fungsi Minimum\n------------------
------------------------------------------\n');
f=x^4-cos(2*x);
xL=-1;
xu=1;
eps=10^-5;
fprintf('\niterasi x1 x2
xL xu error\n');
error=1;
i=1;
while error>eps
d=((sqrt(5)-1)/2)*(xu-xL);
x1=xL+d;
x2=xu-d;
fx1=subs(f,x,x1);
fx2=subs(f,x,x2);
fxu=subs(f,x,xu);
fxL=subs(f,x,xL);
fprintf(' %4.0f %5.4f %5.4f
%5.4f %5.4f
%5.4f\n',i,x1,x2,xL,xu,error);
if fx1>fx2
xu=x1;
else
xL=x2;
end
error=abs(xu-xL);
i=i+1;
end
fprintf('\nJadi :\nSetelah %d iterasi, f(x) optimal di
x = %5.4f \n',i-1,xu);
clf;
gbr=ezplot(f);
grid on;
title('Golden
search','color','r','fontsize',16,'fontname','Verdana')
;
hold on;
set(gbr,'linewidth',2,'color','r');
plot(xu,fxu,'o','color','k','markerfacecolor','y','line
width',2);
hold on;
plot(xL,fxL,'o','color','k','markerfacecolor','y','line
width',2);
clear all;
clc;
syms x;
fprintf('Penyelesaian nomor 2\ndengan menggunakan
Metode Aproksimasi Kuadrat\n---------------------------
--------------------------\n');
f=x^3-4*x;
h=0.2;
x0=1;
eps=10^-8;
fprintf('\n i x0 x1 x2
f(x0) f(x1) f(x2) x3
f(x3)\n');
i=1;
while abs(h)>eps
x1=x0+h;
x2=x0+2*h;
f0=double(subs(f,x,x0));
f1=double(subs(f,x,x1));
f2=double(subs(f,x,x2));
x3=h*(3*f0-4*f1+f2)/(2*f0-4*f1+2*f2);
f3=double(subs(f,x,x3));
fprintf('%4.0f %5.5f %5.5f %5.5f
%5.5f %5.5f %5.5f %5.5f
%5.5f\n',i,x0,x1,x2,f0,f1,f2,x3,f3);
x0=x0+x3;
h=x3;
i=i+1;
end
fprintf('\nJadi :\nSetelah %d iterasi, f(x) optimal di
x = %5.5f \n',i-1,x3);
clf;
gbr=ezplot(f);
set(gbr,'linewidth',3,'color','r');
axis([-2 2 -4 4]);
grid on;
title('Metode Aproksimasi
Kuadrat','color','k','fontsize',16,'fontname','Verdana'
);
hold on;
plot(x0,f0,'o','color','g','markerfacecolor','y','linew
idth',3);
hold on;
plot(x1,f1,'o','color','g','markerfacecolor','m','linew
idth',3);
hold on;
plot(x2,f2,'o','color','b','markerfacecolor','c','linew
idth',3);
BAB III
PEMBAHASAN
Soal :
xL = –0.236067977 xu = 1
iterasi 2 :
√5−1
d= 2
(𝑥𝑢 − 𝑥𝑙 )
= 0.618033988 (1 – (–0.236067977)
= 0.618033988 (1.236067977)
= 0.763932021
x1 = xL + d
= –0.236067977 + 0.763932021
= 0.527864044
x2 = xu – d
= 1 – 0.763932021
= 0.236067979
f(x1) = (0.527864044)4 – cos (2(0.527864044))
= 0.077640499 – cos (1.055728088)
= 0.077640499 – 0.492594235
= –0.414953736
f(x2) = (0.236067979)4 – cos (2(0.236067979))
= 0.003105620094 – cos (0.472135958)
= 0.003105620094 – 0.890598909
= –0.887493288
Tabel iterasi :
i Id xL xu x1 x2
1 1.23606798 –1 1 0.23606798 –0.23606798
Fungsi f(x1) dan f(x2) –0.8874933 –0.8874933
(1) –3 = A + B + C + D menjadi A + B + C = –3
(2) 3 = –A + B – C + D menjadi –A + B – C = 3
(3) 0 = –8A + 4B – 2C + D menjadi –8A + 4B – 2C = 0
Eliminasi persamaan (1) dan (2) :
A + B + C = –3
–A + B – C = 3 +
B=0
A + B + C = –3 | x 2 | 2A + 2B + 2C = –6
–8A + 4B – 2C = 0 | x 1 | –8A + 4B – 2C = 0 +
–6A + 6B = –6
–6A = –6
A=1
A + B + C + D = –3 1 + 0 + C + 0 = –3
C = –4
Iterasi 2 : h = x3 = 0.15
x0 = x0 + x3
= 1 + 0.15 = 1.15 f0 = (1.15)3 – 4(1.15) = –3.079125
x1 = x0 + h
= 1.15 + 0.15 = 1.3 f1 = (1.3)3 – 4(1.3) = –3.003
x2 = x0 + 2h
= 1.15 + 2(0.15) = 1.45 f2 = (1.45)3 – 4(1.45) = –2.751375
h(3𝑓0 −4𝑓1 +𝑓2 )
x3 = 2𝑓0 −4𝑓1 +2𝑓2
0.15(3(–3.079125)−4(–3.003)+(–2.751375))
= 2(–3.079125)−4(–3.003)+2(–2.751375)
= 0.009935897436 f3 = (x3)3 – 4(x3) = –0.039742608
Tabel iterasi :
i x0 x1 x2 x3
start
Input xL, xu, eps
i = 1 , error = 1
Tidak
error > eps End
Ya
d = (√𝟓 − 1) / 2
x1 = xL + d
x2 = xu – d
A
f(xL) = xL^4 – cos(2*xL)
Tidak
f(x1) > f(x2)
Ya
xL = x2
xu = x1
Cetak error
i=i+1
Hasil plot :
2. Metode aproksimasi kuadrat
start
i=1
Tidak
abs(h) > eps
Ya End
x1 = x0 + h
x2 = x0 + 2*h
f0 = x0^3 – 4*x0
f1 = x1^3 – 4*x1
f2 = x2^3 – 4*x2
A
A
f3 = x3^3 – 4*x3
x0 = x0 + x3
h = x3
i=i+1
Plot :