1) Penjumlahan Matriks
program matrik_penjumlahan;
2) Perkalian Matriks
program matrik_penjumlahan;
uses wincrt;
var a,b,c: array[1..10,1..10] of integer;
i,j,k1,k2,b1,b2,sum,r:integer;
write('Masukkan baris Matrik A = ');readln(b1);
write('Masukkan kolom Matrik A = ');readln(k1);
write('Masukkan baris Matrik B = ');readln(b2);
write('Masukkan kolom Matrik B = ');readln(k2);
for i:=1 to b1 do
for j:=1 to k1 do
readln(a[i,j]);
writeln;
for i:=1 to b2 do
for j:=1 to k2 do
readln(b[i,j]);
writeln;
writeln('Matrik A');
writeln('==================');
for i:=1 to b1 do
begin
for j:=1 to k1 do
write(a[i,j],' ');
writeln;
end;
writeln;
writeln('Matrik B');
writeln('===================');
for i:=1 to b2 do
begin
for j:=1 to k2 do
write(b[i,j],' ');
writeln;
end;
writeln;
writeln('Matrik A*B');
writeln('================');
for i:=1 to b1 do
begin
for j:=1 to k2 do
begin
sum:=0;
for r:=1 to k1 do
sum:=sum+a[i,r]*b[r,j];
c[i,j]:=sum;
write(c[i,j]:2,' ');
end;
writeln;
end;
end.2) Perkalian Matriks
program perkalian_matriks;
uses wincrt;
var A,B,c: array [1..10,1..10] of integer;
i,j,b1,k1,b2,k2,r,sum:integer;
begin
write('masukkan jumlah baris matriks 1 :
');readln(b1);
write('masukkan jumlah kolom matriks 1 : ');readln(k1);
write('masukkan jumlah baris matriks 2 :
');readln(b2);
write('masukkan jumlah kolom matriks 2 :
');readln(k2);
for i:=1 to b1 do
for j:=1 to k1 do
readln(A[i,j]);
for i:=1 to b2 do
for j:=1 to k2 do
readln(B[i,j]);
writeln;
writeln('matriks 1');
writeln('=========');
for i:=1 to b1 do
for j:=1 to k1 do
writeln(A[i,j]);
writeln;
writeln('matriks 2');
writeln('=========');
for i:=1 to b2 do
for j:=1 to k2 do
writeln(B[i,j]);
writeln('matriks A*B');
writeln('=========');
for i:=1 to b1 do
begin
for j:=1 to k2 do
begin
sum:=0;
for r:=1 to k1 do
sum:=sum+A[i,r]*B[r,i];
c[i,j]:=sum;
write(c[i,j]:2, ' ');
end;
writeln;
end;
end.
3) Transpose Matriks
program matriks;
uses wincrt;
var
A,B,C,D : array [1..10,1..10] of integer;
i,j,k,l : integer;
n,p,g : integer;
begin
writeln('matriks 1');
read(n);read(p);writeln;
for i:=1 to n do begin
for j:=1 to p do begin
readln(A[i,j]);
end;
end;
for i:=1 to n do begin
for j:=1 to p do begin
write(A[i,j]:5);
end;writeln;
end;
writeln;
writeln('matriks transpose');
for k:=1 to p do begin
for l:=1 to n do begin
write(A[l,k]:5); B[k,l]:=A[l,k];
end;writeln;
end;
writeln;
for i:=1 to n do begin
for j:=1 to n do begin C[i,j]:=0;
for k:=1 to p do begin
C[i,j]:=C[i,j]+A[i,k]*B[k,j];
end;end;end;
for i:=1 to n do begin
for j:=1 to n do begin
write(C[i,j]:5);
end;writeln;
end;
end.
4) Invers Matriks
program matriks;
uses wincrt;
var
x,adj: array[1..10,1..10] of integer;
i,j,det: integer;
begin
for i:= 1 to 2 do
for j:= 1 to 2 do
readln (x[i,j]);
clrscr;
writeln ('matriks=');
for i:= 1 to 2 do
begin
for j:= 1 to 2 do
write(x[i,j]:4,' ');
writeln;
end;
det:= x[1,1]*x[2,2]-x[1,2]*x[2,1];
writeln ('determinan=', det);
adj [1,1]:= x[2,2];
adj [1,2]:=-x[1,2];
adj [2,1]:=-x[2,1];
adj [2,2]:= x[1,1];
writeln;
writeln ('matriks adjoin=');
for i:= 1 to 2 do
begin
for j:= 1 to 2 do
write (adj[i,j]:4,' ');
writeln;
end;
writeln;
writeln ('invers matriks=');
for i:= 1 to 2 do
begin
for j:= 1 to 2 do
write (adj[i,j]/det:8:2,' ');
writeln;
end;
end.
Tidak ada komentar:
Posting Komentar