Hey, what's going on?

Numerical Methods in Pascal: Root Finding by Regula False (RF)

Posted by Syeilendra Pramuditya on April 25, 2014

Program RegulaFalse;
{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 akar:real;var iter : integer);
var err : real;
begin
iter := 0;
repeat
inc(iter);
akar := a - f(a)*( (b-a) / (f(b) - f(a)) );
err := abs(f(akar));
if (f(a) * f(akar) < 0) then
b := akar
else
a := akar;
until (err < 1e-6) OR (iter = 10000);
end;

Procedure TulisOutput(akar:real);
begin
writeln('Akar = ',akar:10:3);
end;

var a,b,akar : real;
    iter : integer;

begin
clrscr;
BacaInput(a,b);
Proses(a,b,akar,iter);
TulisOutput(akar);
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: