Вы находитесь на странице: 1из 1

Program secant;

Type
Real = Extended;

Function f(x: Real): Real;


Begin
f := x - exp(1.0E0/x);
End;

Var
eps,x,x0,x1: Real;
flag,iter,maxiter: Integer;

Begin
Write('Harga-harga awal x0 : ');
Readln(x0);
Write('Harga-harga awal x1 : ');
Readln(x1);
Write('Jumlah Iterasi Maksimum : ');
Readln(maxiter);
Write('Epsilon/kriteria proses : ');
Readln(eps);

iter := 0;
flag := 0;

While (flag = 0) DO
Begin
x := x1 - f(x1)*(x1 - x0)/(f(x1) - f(x0));
IF (ABS(x-x1) <= eps ) THEN
flag := 1
ELSE IF (iter > maxiter) THEN
flag := 2
ELSE
BEGIN
iter := iter + 1;
x0 := x1;
x1 := x;
End
End;

Writeln('x0 = ',x0);
Writeln('x1 = ',x1);
Writeln('x = ',x);
Writeln('f(x) = ',f(x));
Writeln('Flag = ',flag);
Writeln('Jumlah iterasi = ',iter);

End.

Вам также может понравиться