Anda di halaman 1dari 1

clc, clear

disp('Metode Biseksi')
disp('Untuk mencari akar persamaan')
disp('')
disp('====================================================')
disp ('Persamaan nonlinear')
f=inline('log(x+1)+x^2','x')
ezplot(f)
grid on
a=input ('masukkan batas bawah interval= ');
b=input ('masukkan batas atas interval= ');
if f(a)*f(b)>0
disp ('interval tidak mengapit akar')
disp('ulangi lagi masukkan interval...!')
elseif f(a)*f(b)<0
e=input('masukkan batas toleransi maksimum abs(f(xt))= ')
disp('=====================================================')
disp('')
xa(1)=a;
xb(1)=b;
xt(1)=(xa+xb)/2;
g(1)=nan;
i=1;
while abs(f(xt(i)))>e
if f(xa(i)*f(xt(i)))<=0
xa(i+1)=xa(i);
xb(i+1)=xt(i);
else
xa(i+1)=xt(i);
xb(i+1)=xb(i);
end
xt(i+1)=(xa(i+1)+xb(i+1))/2;
g(i+1)=xt(i+1)-xt(i);
i=i+1;
end
disp('hasil komputasi: ')
disp('iterasi xa xb xt f(xa) f(xb) f(xt) galat')
disp([[1:i]' xa' xb' xt' f(xa)' f(xb)' f(xt)' g'])
disp('====================================================')
fprintf('akar persamaannya adalah=%3.4f\n',xt(i))
end