program Gauss_Pivot_Parsial_The_Queen_of_Science;
uses wincrt;
var
i, j, k, n, y, z, cek : integer;
r, s, jumlah, max : real;
x : array[0..20,0..20] of real;
akar : array[0..20] of real;
label 1, 2, 3, 4, 5;
begin
1:
{Input awal: orde dan elemen-elemen dari matriks}
writeln('Masukkan orde matriks anda. (Xnn dengan maksimal 20x20)');
write('n = ');readln(n);
writeln('Masukkan elemen-elemen matriks anda.');
for i := 1 to n do
begin
for j := 1 to n+1 do
begin
write('a',i,'',j,' = ');readln(x[i,j]);
end;
end;
clrscr;
2:
{Cetak matriks}
for i := 1 to n do
begin
write('|');
for j := 1 to n+1 do
begin
write(' ',x[i,j]:0:4);
end;
writeln(' |');
end;
if y = 0 then
begin
writeln('');
writeln('Benarkah ini matriks yang anda inginkan? 1. Ya 2. Tidak');readln(y);
if y = 1 then
begin
clrscr;z:= 1;goto 2;
end;
if y = 2 then
begin
clrscr;goto 1;
end;
end;
writeln('');
writeln('');
{Proses pencarian akar-akar dari SPL yang diberikan}
for i:= 1 to n-1 do
begin
{Cek apakah matriks merupakan matriks singular}
for j:= i to n do
begin
if x[i,j] = 0 then cek:= cek + 1;
end;
if cek = n then
begin
writeln('Mariks singular.');
end;
max:= 0;
{Pencarian nilai maksimum}
for j:= i to n-1 do
begin
if abs(max) < abs(x[j+1,i]) then
begin
max:= x[j+1,i];z:= j+1;
end;
end;
for k:= i to n+1 do
begin
s:= x[z,k];
x[z,k]:= x[i,k];
x[i,k]:= s;
end;
{Proses OBE}
for j:= i+1 to n do
begin
r:= x[j,i]/x[i,i];
for k:= i to n+1 do
begin
x[j,k]:= x[j,k] - r*x[i,k];
end;
end;
end;
{Penyulihan mundur}
akar[n]:= x[n,n+1]/x[n,n];
for i:= n-1 downto 1 do
begin
jumlah:= 0;
for j:= i to n do
begin
jumlah:= jumlah + x[i,j]*akar[j];
end;
akar[i]:= (x[i,n+1] - jumlah)/x[i,i];
end;
{Pencetakan akar}
writeln('Jadi, akar-akar dari SPL yang diberikan adalah');
for i:= 1 to n do
begin
writeln('X',i,' = ',akar[i]:0:4);
end;
3:
{Optional}
writeln('');
writeln('');
writeln('Ingin mencoba lagi? 1. Ya 2. Tidak');readln(y);
if y = 1 then
begin
clrscr;y:= 0;cek:= 0;goto 1;
end
else
begin
writeln('');
writeln('Terima kasih sudah menggunakan program ini.');
end;
Tidak ada komentar:
Posting Komentar