Program hitung_secant;
uses wincrt;
function f(x:real):real;
begin
f:=(((sqr(x))*x)+(sqr(x))-(3*(x))-3);
end;
function ff(x:real):real;
begin
ff:=((3*(sqr(x)))+(2*(x))-3);
end;
function error(x1,x2:real):real;
var
err:real;
begin
err:=(((x2-x1)/x2)*100);
if err<0 then
error:=err*(-1)
else
error:=err;
end;
function hitxc(xa:real):real;
begin
hitxc:=(xa-(f(xa)/ff(xa)));
end;
procedure pilakar(var xa:real;xc:real);
begin
xa:=xc;
end;
procedure lanjut(var it:integer; var xc1,xc2:real;xc:real);
begin
it:=it+1;
xc1:=xc2;
xc2:=xc;
end;
var
x1,emin,er,xc,xc1,xc2,a,b,c:real;
iterasi:integer;
begin
write('masukan x1 : ');readln(x1);
write('masukan error min : ');readln(emin);
iterasi:=0;
er:=100;
xc1:=0;
xc2:=0;
clrscr;
writeln('|ite | xi | f(xi) | f"(xi) | xc | f(xc) | eror |');
while (er > emin) do
begin
xc:=hitxc(x1);
a:=f(x1);
c:=f(xc);
b:=ff(x1);
lanjut(iterasi,xc1,xc2,xc);
if (iterasi<2) THEN
writeln('| ',iterasi,' | ',x1:0:5,'| ',a:0:5,'| ',b:0:5,'| ',xc:0:5,'| ',c:0:5,'| |')
else
begin
er:=error(xc1,xc2);
writeln('| ',iterasi,' | ',x1:0:5,'| ',a:0:5,'| ',b:0:5,'| ',xc:0:5,'| ',c:0:5,'| ',er:0:5,' |');
end;
pilakar(x1,xc);
end;
writeln;
writeln('jawaban = ',xc:0:5);
end.
uses wincrt;
function f(x:real):real;
begin
f:=(((sqr(x))*x)+(sqr(x))-(3*(x))-3);
end;
function ff(x:real):real;
begin
ff:=((3*(sqr(x)))+(2*(x))-3);
end;
function error(x1,x2:real):real;
var
err:real;
begin
err:=(((x2-x1)/x2)*100);
if err<0 then
error:=err*(-1)
else
error:=err;
end;
function hitxc(xa:real):real;
begin
hitxc:=(xa-(f(xa)/ff(xa)));
end;
procedure pilakar(var xa:real;xc:real);
begin
xa:=xc;
end;
procedure lanjut(var it:integer; var xc1,xc2:real;xc:real);
begin
it:=it+1;
xc1:=xc2;
xc2:=xc;
end;
var
x1,emin,er,xc,xc1,xc2,a,b,c:real;
iterasi:integer;
begin
write('masukan x1 : ');readln(x1);
write('masukan error min : ');readln(emin);
iterasi:=0;
er:=100;
xc1:=0;
xc2:=0;
clrscr;
writeln('|ite | xi | f(xi) | f"(xi) | xc | f(xc) | eror |');
while (er > emin) do
begin
xc:=hitxc(x1);
a:=f(x1);
c:=f(xc);
b:=ff(x1);
lanjut(iterasi,xc1,xc2,xc);
if (iterasi<2) THEN
writeln('| ',iterasi,' | ',x1:0:5,'| ',a:0:5,'| ',b:0:5,'| ',xc:0:5,'| ',c:0:5,'| |')
else
begin
er:=error(xc1,xc2);
writeln('| ',iterasi,' | ',x1:0:5,'| ',a:0:5,'| ',b:0:5,'| ',xc:0:5,'| ',c:0:5,'| ',er:0:5,' |');
end;
pilakar(x1,xc);
end;
writeln;
writeln('jawaban = ',xc:0:5);
end.
No comments:
Post a Comment