Source code :
disp ('Nama : Desianny Amalia Fauziah');
disp ('NIM : 5302413085');
disp ('Prodi : PTIK');
disp ('Rombel : 02');
disp ('==============================================================');
disp ('====== MENGHITUNG AKAR PERSAMAAN DENGAN METODE BISECTION =====');
disp ('==============================================================');
xi = 0.5;
xu = 1.5;
galat = 0.01;
f = inline ('exp(x)-2-(x.^2)');
literasi = 1;
error = 1;
t = 0;
r = 0;
disp ('==============================================================');
disp ('No. xi xu xr f(xi) f(xu) f(xr) ');
disp ('==============================================================');
while error > galat
xr = (xi+xu) / 2;
t = xr;
disp(sprintf('%1g %.4f %.4f %.4f %.4f %.4f %.4f', literasi, xi, xu, xr, f(xi), f(xu), f(xr)))
if f(xi)*f(xr)<0
xu = xr;
elseif f(xi)*f(xr)>0
xi = xr;
elseif f(xi)*f(xr)==0
exit
end
xr = (xi+xu)/2;
r = xr;
literasi = literasi+1;
e = (r-t)/r;
error(literasi) = abs(e);
end
disp(sprintf('Akar dari persamaan adalah %1.8f',xr))
plot(error);
x = xr;
err = error (literasi);
thanks :)
BalasHapusterimakasih kak, sangat membatu sekali untuk buat tugas kuliah, rajin rajin nulis di blog ya :D
BalasHapuskak, kalau di implementasikan jadi gui gmn ya?
BalasHapusmasihh belajar matlab heheh