Operasi Matrik
Operasi Matrik
OPERASI MATRIKS
>> A,B
A =
0 1
2 3
B =
4 5
6 7
y =
100
10
1
Tabel 4. 1
dot(x,y) menghitung dot-product dari vektor x dan y
cross(x,y) menghitung cross-product dari vektor x dan y
x1 – 2 x2 = 32
12 x1 + 5 x2 = 7
40 Operasi Matriks
1 − 2 x1 32
= ⇔ AX = B
12 5 x2 7
>> X=inv(A)*B
X =
6.0000
-13.0000
>> X=A\B
X =
6.0000
-13.0000
x + 2y + 3z = 2
4x + 5y + 6z = -5,5
7x + 8y – 9z = -49
4.4 Transposisi
Tabel 3. 1
petik tunggal ( ‘ ) operasi transposisi untuk matriks berisi bilangan
riil, atau transposisi dan konjugasi untuk matriks
kompleks.
titik-petik ( .’ ) operasi transposisi tanpa konjugasi. Untuk
matriks riil, operator ini memberi hasil yang
sama dengan petik tunggal
>> Transp_riil=Mat_riil',Transp_kompleks=Mat_kompleks'
Transp_riil =
1 3
0 5
Transp_kompleks =
1.0000 - 2.0000i 1.0000
0 - 3.0000i 2.0000 - 3.0000i
>> Transp_riil2=Mat_riil.'
Transp_riil2 =
1 3
0 5
>> Transp_kompleks2=Mat_kompleks.'
Transp_kompleks2 =
1.0000 + 2.0000i 1.0000
0 + 3.0000i 2.0000 + 3.0000i
Tabel 3. 2
+ – Tambah dan kurang (elemen-per-elemen)
.* ./ .\ Kali, bagi, bagi terbalik (elemen-per-elemen)
.^ Pangkat (elemen-per-elemen)
>> A+B
ans =
8 3
3 5
>> A.*B
ans =
7 -10
2 0
>> B./A
ans =
7.0000 -2.5000
2.0000 0
>> B.^2
ans =
49 25
4 0
>> A.^B
ans =
1 -32
1 1
>> 2.^B
ans =
128 32
4 1
>> a.*b
ans =
12 10 6
>> c.*d
ans =
50
200
450
>> a.*c
??? Error using ==> .*
Matrix dimensions must agree.
>> c./2.*d.^2
ans =
125
1000
3375
>> n=-3:3
n =
-3 -2 -1 0 1 2 3
>> rem(n,3)
ans =
0 -2 -1 0 1 2 0
Contoh Kasus
y = ln(x2)
>> clear
>> inkremen = 0.5;
>> x = -100:inkremen:100; %Di sini kita definisikan x,
>> y = log(x.^2); %kemudian kita hitung y
Warning: Log of zero.
>> y = log(x.^2+eps);
Columns 8 through 9
1.5000 2.0000
Columns 8 through 9
0.8109 1.3863
>> clear
46 Operasi Matriks
>> x=0:30:360;
>> x=[x 45 135 225 315];
>> x=sort(x)
x =
Columns 1 through 13
0 30 45 60 90 120 135 150 180 210 225 240 270
Columns 14 through 17
300 315 330 360
>> t=x.*pi/180;
>> y1=sin(t); y2=cos(t);
>> tabel=[x;y1;y2]';
>> judul=' sudut sin cos';
Ingat, vektor x, y1, dan y2 berupa satu baris; padahal kita ingin
menampilkannya memanjang ke bawah berupa kolom, jadi perlu
dilakukan transposisi.
Soal Latihan