Program Pascal Edisi Spesial Matrik
PROGRAM PASCAL EDISI SPESIAL MATRIK
Pada postingan kali ini saya akan menyuguhkan program-program khusus operasi matriks. Seperti yang kita tahu, perhitungan operasi matrik sangat beragam. Mulai dari pengurangan, penjumlahan, perkalian, determinan, tranpose matrik, dan invers. Untuk mempermudah perhitungan matrik, mari kita coba membuat program dengan bantuan Turbo Pascal.
Program yang pertama tentang bagaimana menampilkan sebuah matrik
program matriks;
uses wincrt;
var
bar,col,i,j:integer;
a:array[1..20,1..20] of real;
begin
write ('baris yang diinginkan?');
readln (bar);
readln (col);
for i:=1 to bar do
begin
for j:=1 to col do
begin
readln (a[i,j]);
end;
end;
writeln('matriksnya adalah:');
for i:=1 to bar do
begin
for j:=1 to col do
begin
write (a[i,j]:0:0,' ');
end;
writeln;
end;
end
end
Program yang kedua tentang bagaimana mencari matrik tranpose
program matriks_transpose;
uses wincrt;
var
bar,col,i,j:integer;
a,b:array[1..20,1..20] of real;
begin
write ('baris yang diinginkan?');
readln (bar);
write ('colom yang diinginkan?');
readln (col);
for i:=1 to bar do
begin
for j:=1 to col do
begin
readln (a[i,j]);
end;
end;
writeln('matriks aslinya adalah:');
for i:=1 to bar do
begin
for j:=1 to col do
begin
write (a[i,j]:0:0,' ');
end;
writeln;
end;
writeln ('matriks transposenya adalah:');
for i:=1 to col do
begin
for j:=1 to bar do
begin
b[i,j]:=a[j,i];
end;
end;
for i:=1 to col do
begin
for j:=1 to bar do
begin;
write (b[i,j]:0:0,' ');
end;
writeln;
end;
end.
Program yang ketiga tentang bagaimana menghitung pengurangan dan penjumlahan matrik
program penjumlahan_pengurangan_matrix;
uses wincrt;
type
larik=array[1..25,1..25] of real;
var
i,j,k:byte;
bar,col:byte;
a,b,c,d,e:larik;
begin
write ('baris matrik ? ');readln(bar);
write ('kolom matrik ? ');readln(col);
writeln;
{menginput nilai matrik pertama}
writeln ('matrik pertama');
for i:=1 to bar do
begin
for j:=1 to col do
begin
write ('nilai[',i,',',j,']');
readln(a[i,j]);
end;
writeln;
end;
writeln;
{menginput nilai matrik kedua}
writeln ('matrik kedua');
writeln;
for i:=1 to bar do
begin
for j:=1 to col do
begin
write ('nilai[',i,',',j,']');
readln(b[i,j]);
end;
writeln;
end;
writeln;
{menjumlahkan matrik}
writeln;
for i:=1 to bar do
begin
for j:=1 to bar do
begin
for k:=1 to col do
d[i,j]:=a[i,j]+b[i,j]
end;
end;
{mengurangkan matrik}
writeln;
for i:=1 to bar do
begin
for j:=1 to bar do
begin
for k:=1 to col do
e[i,j]:=a[i,j]-b[i,j]
end;
end;
clrscr;
{menampilkan matrik pertama}
writeln ('matrik pertama:');
for i:=1 to bar do
begin
for j:=1 to col do
begin
write (a[i,j]:0:0,' ');
end;
writeln;
end;
{menampilkan matrik kedua}
writeln ('matrik kedua:');
for i:=1 to bar do
begin
for j:=1 to col do
begin
write (b[i,j]:0:0,' ');
end;
writeln;
end;
{menampilkan hasil penjumlahan}
writeln ('hasil penjumlahan matrik:');
writeln;
for i:=1 to bar do
begin
for j:=1 to col do
write(d[i,j]:9:2);
writeln;
end;
{menampilkan hasil pengurangan}
writeln ('hasil pengurangan matrik:');
writeln;
for i:=1 to bar do
begin
for j:=1 to col do
write(e[i,j]:9:2);
writeln;
end;
end.
Program yang keempat tentang bagaimana menentukan determinan matrik
program determinan;
uses wincrt;
var A : array[1..2,1..2] of integer;
j,k,D : integer;
begin
For j:=1 to 2 do
begin
writeln('Entrikan baris ',j,' matriks A : ');
readln(A[j,1] , A[j,2]);
end;
writeln ('matriknya:');
For j:=1 to 2 do
begin
For k:=1 to 2 do write(A[j,k] : 5);
writeln;
end;
writeln;writeln;writeln;
D := A[1,1]*A[2,2] - A[1,2]*A[2,1];
writeln('Det(A) = ',D);
end.
Program yang kelima tentang bagaimana menentukan determinan sekaligus invers matrik
program invers_determinan;
uses wincrt;
var a,b,c,d,i,invers,p,q,r,s:real;
jawab:char;
pass:string[8];
begin
clrscr;gotoxy(20,1);
writeln('Mencari Invers Matriks Ordo 2x2 ');
gotoxy(10,5);write('a=');read(a);
gotoxy(18,5);write('b=');read(b);
gotoxy(10,7);write('c=');read(c);
gotoxy(18,7);write('d=');read(d);
i:=(a*d)-(b*c);
gotoxy(24,8);write('determinan= ',i);
writeln;
if not(i=0) then
begin
invers:=1/((a*d)-(b*c));
p:=d*invers;
q:=-b*invers;
r:=-c*invers;
s:=a*invers;
gotoxy(25,10);writeln('Invers matriks A =');
gotoxy(10,13);write(p:0:3);
gotoxy(18,13);write(q:0:3);
gotoxy(10,16);write(r:0:3);
gotoxy(18,16);write(s:0:3);
end
else
begin
gotoxy(25,15);
writeln('Tidak ada invers matriks');
end;
2 komentar:
terimakasih ,, sangat membantu blog nya
mkasih..infox..sangat membantu...tp mau nax...klu untuk matriks identitas g mana yah? mhon bantuan x yah...
Posting Komentar