program bagidua;
uses wincrt;
Var
a,b,c,F_a,F_b,F_c,E : real;
max,it : integer;
epsilon: real;
selang :string;
function f(x : real) : real;
Begin
f := (x*x*x*x*x) - x - 1;
End;
Begin
write (' Batas bawah = '); read(a);
write (' Batas atas = '); read(b);
write (' Toleransi Error = '); read(E);
write (' Iterasi maksimum = '); read(max);
clrscr;
it := 0;
F_a := f(a);
F_b := f(b);
if (F_a * F_b > 0) then writeln(' Nilai F(a) x F(b) > 0')
else
Begin
writeln('--------------------------------------------------------------------------');
writeln(' r a b c f(a) f(b) f(c) selang lebarnya ' );
writeln('--------------------------------------------------------------------------');
epsilon := E+1;
while((it <= max) and (epsilon > E))
do
Begin
it := it + 1;
c := (a + b) / 2;
F_c := f(c);
if(F_a * F_c <= 0) Then
begin
selang :='CA';
end
else
begin
selang :='CB';
end;
write(it:2,' ',a:8:5,' ',b:8:5,' ',c:8:5,' ');
writeln(F_a:8:5,' ',F_b:8:5,' ',F_c:8:5,' ',selang:4,' ',(c-a):8:5);
epsilon :=(c-a);
if(F_a * F_c <= 0) Then
Begin
b := c;
F_b := F_c
End
else
Begin
a := c;
F_a := F_c
End;
End;
writeln;
if(it<=max) Then
Begin
writeln('Hampiran (pendekatan) nilai x = ',c:8:5);
writeln('Pada Iterasi ke-',it);
End
else writeln('Toleransi tidak terpenuhi, jumlah iterasi kurang');
End;
End.
HASIL
Artikel Terkait:
0 komentar:
Posting Komentar