Hey, what's going on?

Numerical Methods in Pascal: Root Finding by Newton-Rhapson (NR)

Posted by Syeilendra Pramuditya on April 25, 2014

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

Function df(x:real):real;
begin
df:=2*x;
end;

Procedure BacaInput(var x:real);
begin
write('Masukan tebakan awal : ');readln(x)
end;

Procedure Proses(var x:real;var iter :integer);
var err:real;
begin
iter := 0;
repeat
 begin
 inc(iter);
 x := x - f(x)/df(x);
 end;
until(abs(f(x)) < 1e-6);
end;

Procedure TulisOutput(x1:real);
begin
writeln('Akarnya adalah : ',x1:10:2);
end;

var x,x1:real;
    iter : integer;
begin
clrscr;
BacaInput(x);
Proses(x,iter);
TulisOutput(x);
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: