Pengen ngeshare
nih gimana sih caranya buat program eliminasi gauss dengan program pascal.
Semoga dapat membantu :)
uses crt;Const
Max = 25;
Type
Matrik = record
Row, col : byte;
Element : array
[1..max, 1..max] of real;
End;
Vektor = record
Row : byte;
Element : array
[1..max] of real;
End;
Var
x, b : vektor;
A : matrik;
n : integer;
c : real;
Error : boolean;
Procedure
masukkandata;
Var i,j : byte;
Begin
Write ('Jumlah
persamaan :');
Readln (n);
A.row := n;
A.col := n ;
b.row := n;
for i := 1 to n
do
begin
writeln
('Persamaan ke ',i );
for j := 1 to n
do
begin
write
('X[',i,',',j,'] = ');
readln
(A.element[i,j]);
end;
write('Y[',i,'] = '); readln(A.element[i,n+1]);
writeln;
end;
end;
procedure
eliminasigauss;
var I,j,k :
integer;
temp, S : real;
Begin
Error := false;
For i := 1 to n
do
Begin
If
(A.element[i,i] = 0 ) then
Begin
write(A.element[i,i])
;
Error := true;
Exit;
End;
temp :=
A.element[i,i];
for k := 1 to n+1
do
begin
A.element[i,k] :=
A.element[i,k] / temp;
end;
For j := 1 to n do
begin
if(j<>i)
then
begin
c :=
A.element[j,i];
for k := 1 to n+1
do
begin
A.element[j,k] :=
A.element [j,k] - (c * A.element[i,k]);
end;
end;
end;
end;
x.row := n;
for i := n downto
1 do
begin
if (A.element
[i,i] = 0.0 ) then
Begin
Error := true;
Exit;
End;
x.element[i] :=
A.element[i,n+1];
end;
end;
Procedure
tulishasil;
Var i : byte;
Begin
If (error) then
Begin
Writeln ('tidak
memenuhi');
End
Else
Begin
Writeln;
Writeln
('Penyelesaian : ');
For i := 1 to
x.row do
Writeln('X',i,' =
',x.element[i]:6:2);
End;
End;
Begin
Masukkandata;
Eliminasigauss;
Tulishasil;
readln;
End.
Itu tuh
sintagnya, sintag ini dapat digunakan untuk mencari akar-akar persamaan dari
beberapa persamaan,tergantung nilai n yang kita masukkan.
Berikut adalah
contoh hasil program dari soal:
2x1 +
3 x2 + 6 x3 = 5
7x1 +
5 x2 +6 x3 = 2
4x1 +
3x2 + 6x3 = 7
Dan jawabannya
adalah
x1 = 1
x2
= -4
selamat mencoba
kawan-kawan :)
thks banget sist atas ilmunya :)
BalasHapus