Anda di halaman 1dari 2

Tugas Minggu Ketiga

Komputasi Numerik

Hasbyallah Maulana Akhyar

1706037283

Rumus di scinotes
clc
clear // Menghapus Memori

function [root]=Bisection(fun, x, tol, maxit)


if fun (x(1))>0 then
xu=x(1);xl=(2);
else
xu=x(2);xl=x(1);
end
Ea=1;
iter=1;
while(1)
xr(iter)= (xl(iter) + xu(iter))/2;
if fun (xr(iter))>0 then
xu(iter+1) = xr(iter);
xl(iter+1) = xl(iter);
elseif fun (xr(iter))<0 then
xl(iter+1)=xr(iter);
xu(iter+1)=xu(iter);
else
break
end
if iter>1 then
Ea(iter)=100*abs((xr(iter)-xr(iter-1))/xr(iter));
end
if Ea(iter)<tol|iter==maxit then
break
end
iter=iter+1;
end
root=xr(iter);
endfunction
function f=fun1(x)
f= x.^3-9*x+1;
endfunction
x=[2 4];
tol=1e-4;
maxit=5;
root=Bisection(fun1,x,tol,maxit);
disp(root,"root")

Hasilnya di command :

root

2.9375

Persamaan dirubah

Setelah diubah persamaannya menjadi

3x^3 + 2X^2-x-9=0
Yang diubah :
function f=fun1(x)
f= 3*x.^3+2*x.^2-x-9;
endfunction
x=[1 2];
tol=1e-4;
maxit=10;
root=Bisection(fun1,x,tol,maxit);
disp(root,"root")

Hasil di Command :

root

1.3173828

Anda mungkin juga menyukai