Hey, what's going on?

Numerical Methods in Pascal: Root Finding by Bisection

Posted by Syeilendra Pramuditya on April 25, 2014

Program Bisection;
{https://syeilendrapramuditya.wordpress.com}
uses crt;
Function f(x:real):real;
begin
f := sqr(x) - 9;
end;

Procedure BacaInput(var a,b:real);
begin
repeat
write('Masukan batas kiri dan kanan : ');
Readln(a,b);
until (f(a)*f(b) < 0);
end;

Procedure Proses(a,b:real;var NewRoot:real;var iter :integer);

begin
iter:=0;
Repeat
begin
 inc(iter);
 NewRoot:=(a+b)/2;
 IF (f(a)*f(NewRoot) < 0) then
 b := NewRoot
 else
 a:=NewRoot;
 end;
until (abs(f(NewRoot)) < 1e-6) OR (iter = 10000);
end;

Procedure TulisAkar(NewRoot:real);
begin
writeln('Akar dari persamaan adalah : ',NewRoot:10:2);
end;

var a,b,NewRoot : real;
    iter:integer;
Begin
clrscr;
BacaInput(a,b);
Proses(a,b,NewRoot,iter);
TulisAkar(NewRoot);
writeln('Iterasi = ',iter:10);
readln;
end.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: