Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

program suntoyo

implicit none
integer:: n,g
real:: x,fx,z
! Program untuk incremental search method
!
write(*,*)'Masukkan awal pengulangan'
read(*,*)g
write(*,*)'Masukkan batas pengulangan'
read(*,*)n
write(*,*)'Masukkan interval'
read(*,*)z
do x=g,n, z
fx=cosh(x)*cos(x)+1
write(*,*) x, fx
end do
read(*,*)
stop
end program suntoyo
matlab
% Bisection Method in MATLAB
a=input('Enter function with right hand side zero:','s');
f=inline(a);
xl=input('Enter the first value of guess interval:') ;
xu=input('Enter the end value of guess interval:');
tol=input('Enter the allowed error:');
if f(xu)*f(xl)<0
else
fprintf('The guess is incorrect! Enter new guesses\n');
xl=input('Enter the first value of guess interval:\n') ;
xu=input('Enter the end value of guess interval:\n');
end
for i=2:1000
xr=(xu+xl)/2;
if f(xu)*f(xr)<0
xl=xr;
else
xu=xr;
end
if f(xl)*f(xr)<0
xu=xr;
else
xl=xr;
end
xnew(1)=0;
xnew(i)=xr;
if abs((xnew(i)-xnew(i-1))/xnew(i))<tol,break,end
end
str = ['The required root of the equation is: ', num2str(xr), '']

You might also like