program Persamaan_non_linier;
uses wincrt;
var
x,x1,x2,xa,xb,xc,y,y1,y2,ya,yb:real;
I,j,k:integer;
replay:char;
pilihan:integer;
x3,y3:real;
begin
repeat
writeln('PILIHAN PROGRAM');
writeln;
writeln('1.program metode biseksi');
writeln('2.program regula falsi');
writeln;
writeln('pilihan anda? ');
readln(pilihan);
if (pilihan=1) then
begin
writeln('tentukan nilai akar persamaan f(x)=x^3+x^2-3x=0 dgn metode biseksi');
write('masukan nilai x1= ');
readln(x1);
y1:=x1*x1*x1+x1*x1-3*x1-3;
writeln(' nilai f(x1)=',y1:0:4);
repeat
begin
write('masukan nilai x2= ');
readln(x2);
y2:=x2*x2*x2+x2*x2-3*x2-3;
write(' nilaif(x2)=',y2:0:4);
end;
if (y1*y2)<0 then
writeln(' nilai ok')
else
writeln(' nilai x2 belum sesuai');
until (y1*y2)<0;
i:=2;
writeln;
writeln('penyelesaian persamaan dgn metode biseksi,nilai x1=',x1:0:2,' & x2=',x2:0:2);
writeln('----------------------------------------------------');
writeln(' n x f(x) error ');
writeln('----------------------------------------------------');
repeat
begin
i:=i+1;x3:=(x1+x2)/2;
y3:=x3*x3*x3+x3*x3-3*x3-3;
if (i mod 10)=0 then readln;
if 1<10 then
writeln('',i,'::',x3,'::',y3,'::',abs(y3),'::')
else writeln(i,'::',x3,'::',y3,'::',abs(y3),'::');
if (y1*y3)<0 then
begin
x2 :=x3;
end else
begin
x1:=x3;
end;
end;
until abs(y3)<1e-07;
writeln('--------------------------------------');
writeln('akar persamaan nya=',x3);
writeln('errornya=',abs(y3));
writeln('--------------------------------------');
write('apakah anda ingin mengulangi?y/n: ');
readln(replay);
end;
if(pilihan=2) then
begin
writeln('tentukan nilai akar dari persamaan f(x)x^3+x^2-3x-3 dengan regula falsi');
write('masukan nilai x1= ');readln(x1);
y1:=x1*x1*x1+x1*x1-3*x1-3;
writeln(' nilai f(x1)=',y1:0:4);
repeat
begin
write('masukan nilai x2= ');readln(x2);
y2:=x2*x2*x2+x2*x2-3*x2-3;
write(' nilai f(x2)=',y2:0:4);
end;
if (y1*y2)<0 then
writeln(' nilai ok')
else
writeln(' nilai x2 belum sesuai');
until (y1*y2)<0;
writeln;
writeln('penyelesaian persamaan karakteristik dengan metode regula falsi');
writeln('------------------------------------------------------');
writeln(' n x f(x) error ');
writeln('------------------------------------------------------');
repeat
begin
i:=i+1;x3:=(x2-(y2/(y2-y1))*(x2-x1));
y3:=x3*x3*x3+x3*x3-3*x3-3;
if i<10 then
writeln('',i,':',x3,':',y3,':',abs(y3),': ')
else
writeln(i,':',x3,':',y3,':',abs(y3),':');
if (y1*y3)<0 then
begin
x2:=x3;y2:=y3;
end
else
begin
x1:=x3;y1:=y3;
end;
end;
until abs(y3)<1e-08;
writeln('-----------------------------------------------------');
writeln('akar persamaan nya=',x3);
writeln('errornya=',abs(y3));
writeln('-----------------------------------------------------');
write('apakah anda ingin mengulangi?y/n: ');
readln(replay);
end;
until replay ='n';
end.
Tidak ada komentar:
Posting Komentar