--

Program Pascal Metnum

Friday, January 22, 2010 mencoba sebuah karya dunia maya
Program Pascal Menghitung akar dengan metode bagi dua dan regulapalsi.
Materi Metode Numerik.
Berikut Source Codenya:

uses crt;
var
a,b:real;
function fungsi(x:real):real;
var
fx:real;
begin
fx:=exp(x)-5*(x*x);
fungsi:=fx;
end;
procedure bagidua(a,b:real);
const ep=0.000000001;
var
c:real;
i:integer;
begin
i:=0;
repeat
inc(i);
c:= (a+b)/2;
if fungsi(c) = 0 then
begin
a:=c;
b:=c;
end;
if fungsi(a)*fungsi(c) < 0 then
b:= c
else
a:=c;
writeln('iterasi:',i);
writeln('a:',a:0:7);
writeln('b:',b:0:7);
writeln('fa:',fungsi(a):0:7);
writeln('fc:',fungsi(c):0:7);
writeln('c:',c:0:7);
writeln;
until abs(a-b) < ep;
writeln('akar X1=',c:0:5);
end;
procedure regulapalsi(a,b:real);
const ep=0.000001;
var
c:real;
i:integer;
begin
i:=0;
repeat
inc(i);
c:=b-(fungsi(b)*(b-a) / (fungsi(b)-fungsi(a)));
if fungsi(c) =0 then
begin
a:=c;
b:=c;
end
else
if fungsi(a)*fungsi(c) < 0 then
b:=c
else
a:=c;
writeln('iterasi:',i);
writeln('a:',a);
writeln('b:',b);
writeln('fa:',fungsi(a));
until abs(a-b) > ep;
writeln('akar x2=',c:0:5);
end;
begin
write('a:');readln(a);
write('b:');readln(b);
bagidua(a,b);
readln;
end.

0 komentar: Program Pascal Metnum

Post a Comment