Program metode_tabulasi

Program metode_tabulasi;
uses wincrt;
label ulang;
var
x,x1,x2,xa,xb,xc,y,y1,y2,ya,yb:real;
I,j,k:integer;
ab:char;
begin
ulang:
clrscr;
writeln('Tentukan akar penyelesaian dengan Metode Tabulasi dari f(x)=x^3-7x+1');
writeln;

write('masukkan nilai x1 ='); { * Nilai variable X pertama * }
readln(x1);
y1 := x1* x1* x1 - 7 * x1 + 1;
Writeln(' f(',x1:0:2,')=',y1:0:4);
repeat
begin
write('masukkan nilai x2 =');
readln(x2);
y2 := x2 * x2 * x2 - 7 * x2 + 1;
writeln(' f(',x2:0:2,')=',y2:0:4);
writeln;
writeln('Syarat (x1*x2)<0');
write(' x1*x2=',y1*y2:0:5);
if (y1*y2)<0 then write(' Nilai OK') else write(' Nilai Tidak Sesuai');
readln;
end;
until(y1 * y2) <0;
clrscr;
k:=0;
repeat
begin
k:=k+1;
if x1 > x2 then
begin
xa := x1;
xb := x2;
end
else
begin
xa := x2;
xb := x1;
end;
xc := (xa - xb) /10;
i:=0;
repeat
begin
i:=i+1;
x := xb + xc * I;
ya := x * x * x - 7 * x +1;
yb :=( x - xc) *(x - xc) *(x - xc) - 7 * (x - xc)+1;
end;
until (ya * yb) <0;
x1 :=x;
x2 :=x - xc;
writeln ('tabulasi ke-',k);
writeln ('--------------------------------------------------------------------------');
writeln (' n x f(x) error');
writeln ('--------------------------------------------------------------------------');
for j:=1 to 9 do
begin
x := xb + xc * (j -1);
y := x * x * x - 7 * x + 1;
writeln (' ',j,':: ',x,' :: ',y,' :: ',abs(y),' ::');
end;
for j:=10 to 11 do
begin
x := xb + xc * (j -1);
y := x * x * x - 7 * x + 1;
writeln (j,':: ',x,' :: ',y,' :: ',abs(y),' ::');
end;
writeln('---------------------------------------------------------------------------');
end;
readln;
until abs(y)<10e-8;
writeln ('akar pendekatannya adalah x=',x);
writeln ('error=',abs(y));
writeln;
write ('apakah anda ingin mengulangi(y/t):');
readln(ab);
if (ab='Y') or (ab='y') then
begin
goto ulang;
end
else
donewincrt;
end.

Soal:
Cari akar-akar penyelesaian dari persamaan nonlinear di bawah ini dengan metode Tabulasi:
1. x3


- x2


- x + 1 = 0 2. 2 - 5x + sinx = 0


Categories:

0 comments:

Post a Comment