Contents
- Matrizen VII: Transponieren
- Matrizen VIII: Funktionen
- Matrizen IX: Lineare Gleichungssysteme
- Matrizen X: Zugriff auf Teilmatrizen
- Matrizen XI: Manipulation von Matrizen und Vektoren
- Matrizen XII: Löschen von Zeilen und Spalten
- Tensoren (Mehrdimensionale Arrays/Matrizen)
- Laden von Matrizen
- Speichern von Variablen in einer Datei
- Logische Operationen
Matrizen VII: Transponieren
Mit Konjugation ' Ohne Konjugation .'
F = rand(3,2) F' F + sqrt(-1)*F F' F = F + sqrt(-1)*F F' F.'
F =
0.0318 0.0971
0.2769 0.8235
0.0462 0.6948
ans =
0.0318 0.2769 0.0462
0.0971 0.8235 0.6948
ans =
0.0318 + 0.0318i 0.0971 + 0.0971i
0.2769 + 0.2769i 0.8235 + 0.8235i
0.0462 + 0.0462i 0.6948 + 0.6948i
ans =
0.0318 0.2769 0.0462
0.0971 0.8235 0.6948
F =
0.0318 + 0.0318i 0.0971 + 0.0971i
0.2769 + 0.2769i 0.8235 + 0.8235i
0.0462 + 0.0462i 0.6948 + 0.6948i
ans =
0.0318 - 0.0318i 0.2769 - 0.2769i 0.0462 - 0.0462i
0.0971 - 0.0971i 0.8235 - 0.8235i 0.6948 - 0.6948i
ans =
0.0318 + 0.0318i 0.2769 + 0.2769i 0.0462 + 0.0462i
0.0971 + 0.0971i 0.8235 + 0.8235i 0.6948 + 0.6948i
Matrizen VIII: Funktionen
Rang der Matrix Determinante Inverse
rank(F) A = [1 , 2 ; 3 , 4] A det(A) inv(A) inv(A)*A
ans =
2
A =
1 2
3 4
A =
1 2
3 4
ans =
-2
ans =
-2.0000 1.0000
1.5000 -0.5000
ans =
1.0000 0
0.0000 1.0000
Matrizen IX: Lineare Gleichungssysteme
b = [1;1] x = inv(A)*b A*x x = A\b
b =
1
1
x =
-1.0000
1.0000
ans =
1.0000
1.0000
x =
-1
1
Matrizen X: Zugriff auf Teilmatrizen
clc A = [1:3; 4:6; 7:9] A(2,1) A(2,:) A(:,3) A([3 1 2], 1:2) diag(A) E = ones(9); E(3:7,3:7) = zeros(5)
A =
1 2 3
4 5 6
7 8 9
ans =
4
ans =
4 5 6
ans =
3
6
9
ans =
7 8
1 2
4 5
ans =
1
5
9
E =
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 0 0 0 0 0 1 1
1 1 0 0 0 0 0 1 1
1 1 0 0 0 0 0 1 1
1 1 0 0 0 0 0 1 1
1 1 0 0 0 0 0 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
Matrizen XI: Manipulation von Matrizen und Vektoren
reshape: spaltenweise Ordnung bleibt gleich
clc A = [1:3; 4:6] A(:) A = reshape(A,3,2) A = reshape(A,1,6) A = reshape(A,2,3) % % tril, triu % clc A = round(5*rand(5,5)) tril(A) triu(A) triu(A,2) triu(A,-1)
A =
1 2 3
4 5 6
ans =
1
4
2
5
3
6
A =
1 5
4 3
2 6
A =
1 4 2 5 3 6
A =
1 2 3
4 5 6
A =
2 4 3 3 2
5 4 4 1 3
0 1 4 1 1
2 2 1 2 4
2 2 3 5 1
ans =
2 0 0 0 0
5 4 0 0 0
0 1 4 0 0
2 2 1 2 0
2 2 3 5 1
ans =
2 4 3 3 2
0 4 4 1 3
0 0 4 1 1
0 0 0 2 4
0 0 0 0 1
ans =
0 0 3 3 2
0 0 0 1 3
0 0 0 0 1
0 0 0 0 0
0 0 0 0 0
ans =
2 4 3 3 2
5 4 4 1 3
0 1 4 1 1
0 0 1 2 4
0 0 0 5 1
Matrizen XII: Löschen von Zeilen und Spalten
clc A B = tril(A,-2) + triu(A,2) A(3,:)=[] A(:,3)=[] whos B=B([1 2 4 5],[1 2 4 5])
A =
2 4 3 3 2
5 4 4 1 3
0 1 4 1 1
2 2 1 2 4
2 2 3 5 1
B =
0 0 3 3 2
0 0 0 1 3
0 0 0 0 1
2 2 0 0 0
2 2 3 0 0
A =
2 4 3 3 2
5 4 4 1 3
2 2 1 2 4
2 2 3 5 1
A =
2 4 3 2
5 4 1 3
2 2 2 4
2 2 5 1
Name Size Bytes Class Attributes
A 4x4 128 double
B 5x5 200 double
C 2x2x2 64 double
E 9x9 648 double
F 3x2 96 double complex
W 1x5 40 double
a 1x4 32 double
alpha 1x1 16 double complex
ans 5x5 200 double
b 2x1 16 double
c 1x6 48 double
dt 1x1 8 double
f 1x1 1 logical
g 1x1 8 double
index 1x3 24 double
s 4x1 32 double
t 1x1 1 logical
tt 1x7 56 double
u 1x10 80 double
v 1x2 32 double complex
w 1x7 56 double
x 2x1 16 double
y 1x4 32 double
z 1x4 64 double complex
B =
0 0 3 2
0 0 1 3
2 2 0 0
2 2 0 0
Tensoren (Mehrdimensionale Arrays/Matrizen)
clc C(:,:,1) = [1 2; 3 4] C(:,:,2) = [5 6; 7 8] whos zeros(2,2,2,2) whos
C(:,:,1) =
1 2
3 4
C(:,:,2) =
5 6
7 8
C(:,:,1) =
1 2
3 4
C(:,:,2) =
5 6
7 8
Name Size Bytes Class Attributes
A 4x4 128 double
B 4x4 128 double
C 2x2x2 64 double
E 9x9 648 double
F 3x2 96 double complex
W 1x5 40 double
a 1x4 32 double
alpha 1x1 16 double complex
ans 5x5 200 double
b 2x1 16 double
c 1x6 48 double
dt 1x1 8 double
f 1x1 1 logical
g 1x1 8 double
index 1x3 24 double
s 4x1 32 double
t 1x1 1 logical
tt 1x7 56 double
u 1x10 80 double
v 1x2 32 double complex
w 1x7 56 double
x 2x1 16 double
y 1x4 32 double
z 1x4 64 double complex
ans(:,:,1,1) =
0 0
0 0
ans(:,:,2,1) =
0 0
0 0
ans(:,:,1,2) =
0 0
0 0
ans(:,:,2,2) =
0 0
0 0
Name Size Bytes Class Attributes
A 4x4 128 double
B 4x4 128 double
C 2x2x2 64 double
E 9x9 648 double
F 3x2 96 double complex
W 1x5 40 double
a 1x4 32 double
alpha 1x1 16 double complex
ans 4-D 128 double
b 2x1 16 double
c 1x6 48 double
dt 1x1 8 double
f 1x1 1 logical
g 1x1 8 double
index 1x3 24 double
s 4x1 32 double
t 1x1 1 logical
tt 1x7 56 double
u 1x10 80 double
v 1x2 32 double complex
w 1x7 56 double
x 2x1 16 double
y 1x4 32 double
z 1x4 64 double complex
Laden von Matrizen
A = load('examplematrix.dat')
A =
1 2 3
4 5 6
7 8 9
Speichern von Variablen in einer Datei
save
alle Variablen aus dem Workspace
save examplesave.mat % nur ausgewaehlte Variablen save('testsave.mat', 'A')
Logische Operationen
Variablentyp: Wahrheitswert true(=1) oder false(=0) Logisches und && Logisches oder Vergleiche liefern Wahrheitswert 1 oder 0
a=1:4 b=linspace(3,6,4) clc f = false t = true f || t f && t a > c a > b a b find(a > b)
a =
1 2 3 4
b =
3 4 5 6
f =
0
t =
1
ans =
1
ans =
0
Error using > Matrix dimensions must agree. Error in vektorenundmatrizenII (line 111) a > c