Matrixoperationen mit Matlab

In dieser Lektion erkläre ich, wie man Matrixoperationen mit Matlab durchführt.

Zuerst erstellen Sie eine quadratische Matrix M1 mit zwei Zeilen und zwei Spalten.

>> M1=[1 4;2 3]
M 1 =
1 4
2 3

Als Nächstes erstellen Sie eine weitere quadratische Matrix M2 mit zwei Zeilen und zwei Spalten.

>> M2=[3 1;7 5]
M2 =
3 1
7 5

Nun, mit diesen beiden Matrizen M1 und M2, gehen wir einige praktische Beispiele für Matrixberechnungen durch.

Matrixaddition

Um eine Matrixaddition durchzuführen, verwenden Sie den Plusoperator (+).

Geben Sie M1+M2 ein

>> M1+M2
Antwort =
4 5
9 8

$$ M1 + M2 = \begin{pmatrix} 1 & 4 \\ 2 & 3 \end{pmatrix} + \begin{pmatrix} 3 & 1 \\ 7 & 5 \end{pmatrix} = \begin{pmatrix} 1+3 & 4+1 \\ 2+7 & 3+5 \end{pmatrix} = \begin{pmatrix} 4 & 5 \\ 9 & 8 \end{pmatrix} $$

Matrixsubtraktion

Um eine Matrixsubtraktion durchzuführen, verwenden Sie den Minusoperator (-).

Geben Sie M1-M2 ein

>> M1-M2
Antwort =
-2 3
-5 -2

$$ M1 - M2 = \begin{pmatrix} 1 & 4 \\ 2 & 3 \end{pmatrix} - \begin{pmatrix} 3 & 1 \\ 7 & 5 \end{pmatrix} = \begin{pmatrix} 1-3 & 4-1 \\ 2-7 & 3-5 \end{pmatrix} = \begin{pmatrix} -2 & 3 \\ -5 & -2 \end{pmatrix} $$

Matrixmultiplikation

Um eine Matrixmultiplikation durchzuführen, verwenden Sie den Multiplikationsoperator (*).

Geben Sie M1*M2 ein

>> M1*M2
Antwort =
31 21
27 17

$$ M1 \cdot M2 = \begin{pmatrix} 1 & 4 \\ 2 & 3 \end{pmatrix} \cdot \begin{pmatrix} 3 & 1 \\ 7 & 5 \end{pmatrix} = \begin{pmatrix} 1 \cdot 3 + 4 \cdot 7 & 1 \cdot 1 + 4 \cdot 5 \\ 2 \cdot 3 + 3 \cdot 7 & 2 \cdot 1 + 3 \cdot 5 \end{pmatrix} = \begin{pmatrix} 31 & 21 \\ 27 & 17 \end{pmatrix} $$

Beachten Sie, dass Matrixmultiplikation als Zeilen-mal-Spalten-Multiplikation bezeichnet wird.

Sie können nur dann eine Matrixmultiplikation zwischen zwei Matrizen durchführen, wenn die Anzahl der Spalten in der ersten Matrix (M1) gleich der Anzahl der Zeilen in der zweiten Matrix (M2) ist.

Elementweise Matrixmultiplikation

Elementweise Matrixmultiplikation berechnet das Produkt von Elementen, die an derselben Position stehen.

Es handelt sich um eine andere Art der Matrixmultiplikation im Vergleich zur Zeilen-mal-Spalten-Multiplikation.

Um eine elementweise Multiplikation durchzuführen, verwenden Sie den Punktmultiplikationsoperator (.*).

>> M1 .* M2
Antwort =
3 4
14 15

Bei der elementweisen Multiplikation müssen beide Matrizen dieselbe Anzahl an Zeilen und Spalten haben.

$$ M1 \ .* \ M2 = \begin{pmatrix} 1 & 4 \\ 2 & 3 \end{pmatrix} \ .* \ \begin{pmatrix} 3 & 1 \\ 7 & 5 \end{pmatrix} = \begin{pmatrix} 1 \cdot 3 & 4 \cdot 1 \\ 2 \cdot 7 & 3 \cdot 5 \end{pmatrix} = \begin{pmatrix} 3 & 4 \\ 14 & 15 \end{pmatrix} $$

Multiplikation einer Matrix mit einem Skalar

Um das Produkt einer Matrix mit einem Skalar zu berechnen, verwenden Sie den Multiplikationsoperator (*).

Zum Beispiel, geben Sie 2*M1 ein

>> 2*M1
Antwort =
2 8
4 6

Die Elemente der Matrix werden mit der Skalarzahl 2 multipliziert.

$$ 2 \cdot M1 = 2 \cdot \begin{pmatrix} 1 & 4 \\ 2 & 3 \end{pmatrix} = \begin{pmatrix} 2 \cdot 1 & 2 \cdot 4 \\2 \cdot 2 & 2 \cdot 3 \end{pmatrix} = \begin{pmatrix} 2 & 8 \\4 & 6 \end{pmatrix} $$

Matrixdivision

Matrixdivision kann erreicht werden, indem die erste Matrix mit der Inversen der zweiten multipliziert wird, M1·M2-1.

Um die Division zweier Matrizen in Matlab zu berechnen, geben Sie M1*inv(M2) ein

>> M1*inv(M2)
Antwort =
-2.87500 1.37500
-1.37500 0.87500

Alternativ können Sie auch M1/M2 eingeben

In diesem Fall führt Matlab automatisch die Inversion der zweiten Matrix durch.

>> M1/M2
Antwort =
-2.87500 1.37500
-1.37500 0.87500

Das Endergebnis ist immer dasselbe.

Elementweise Matrixdivision

Die elementweise Division berechnet den Quotienten zwischen Elementen, die sich in derselben Position befinden.

Sie stellt eine weitere Art der Matrixdivision dar.

Um eine elementweise Division durchzuführen, verwenden Sie den Operator ./

>> M1 ./ M2
Antwort =
0.33333 4.0000
0.28571 0.6000

Im Falle der elementweisen Division müssen die beiden Matrizen dieselbe Anzahl an Reihen und Spalten haben.

$$ M1 \ ./ \ M2 = \begin{pmatrix} 1 & 4 \\ 2 & 3 \end{pmatrix} \ ./ \ \begin{pmatrix} 3 & 1 \\ 7 & 5 \end{pmatrix} = \begin{pmatrix} \frac{1}{3} & \frac{4}{1} \\ \frac{2}{7} & \frac{3}{5} \end{pmatrix} = \begin{pmatrix} 0.33333 & 0.28571 \\ 4 & 0.6 \end{pmatrix} $$

Matrix durch einen Skalar teilen

Eine Matrix durch einen Skalar zu teilen erfolgt mit dem Divisionsoperator (/).

Zum Beispiel, um die Matrix M1 durch zwei zu teilen, geben Sie M1/2 ein

>> M1/2
Antwort =
0.50000 2.00000
1.00000 1.50000

Alle Elemente der Matrix M1 werden durch die skalare Zahl 2 geteilt.

$$ \frac{M1}{2} = \frac{1}{2} \cdot \begin{pmatrix} 1 & 4 \\ 2 & 3 \end{pmatrix} = \begin{pmatrix} \frac{1}{2} \cdot 1 & \frac{1}{2} \cdot 4 \\ \frac{1}{2} \cdot 2 & \frac{1}{2} \cdot 3 \end{pmatrix} = \begin{pmatrix} 0.5 & 2 \\ 1 & 1.5 \end{pmatrix} $$

Elementweise Matrixpotenzierung

Um jedes Element einer Matrix auf dieselbe Potenz zu erheben,

zum Beispiel, um die Elemente der Matrix M1 auf die Potenz 2 zu erheben, tippen Sie M1.^2

>> M1.^2
Antwort =
1 16
4 9

$$ M1 \ \text{.^} \ 2 = \begin{pmatrix} 1^2 & 4^2 \\ 2^2 & 3^2 \end{pmatrix} = \begin{pmatrix} 1 & 16 \\ 4 & 9 \end{pmatrix} $$

Determinante einer Matrix

Matlab hat eine spezifische Funktion, um die Determinante einer quadratischen Matrix zu berechnen. Das ist die Funktion det().

Zum Beispiel, um die Determinante der Matrix M1 zu berechnen, tippen Sie det(M1)

>> det(M1)
Antwort = -5

$$ \text{det} (M1) = det \begin{pmatrix} 1 & 4 \\ 2 & 3 \end{pmatrix} = 1 \cdot 3 - 4 \cdot 2 = -5 $$

Rang einer Matrix

Um den Rang einer Matrix zu finden, verwenden Sie die Funktion rank().

Zum Beispiel, um den Rang der Matrix M1 zu berechnen, tippen Sie rank(M1)

>> rank(M1)
Antwort = 2

Der Rang ist gleich 2, weil die Determinante der 2x2-Matrix nicht null ist. $$ \text{det} (M1) = det \begin{pmatrix} 1 & 4 \\ 2 & 3 \end{pmatrix} = 1 \cdot 3 - 4 \cdot 2 = -5 $$

Spur einer Matrix

Um die Spur einer Matrix zu berechnen, verwenden Sie die Funktion trace().

Zum Beispiel, um die Spur der Matrix M1 zu berechnen, tippen Sie trace(M1)

>> trace(M1)
Antwort = 4

Die Spur einer Matrix entspricht der Summe der Elemente auf der Hauptdiagonalen. $$ \text{trace} (M1) = \text{trace} \begin{pmatrix} \color{red}1 & 4 \\ 2 & \color{red}3 \end{pmatrix} = 1 + 3 = 4 $$

Transposition einer Matrix

Um die Reihen und Spalten einer Matrix zu transponieren, verwenden Sie die Funktion transpose().

Zum Beispiel, um die Matrix M1 zu transponieren, tippen Sie transpose(M1)

>> transpose(M1)
Antwort =
1 2
4 3

Alternativ können Sie den Matrixtranspositionsoperator verwenden, indem Sie ein Apostroph nach dem Namen der Matrix hinzufügen.

>> M1'
Antwort =
1 2
4 3

In einer transponierten Matrix werden die Reihen der Matrix zu Spalten und umgekehrt. $$ \begin{pmatrix} 1 & 4 \\ 2 & 3 \end{pmatrix}^T = \begin{pmatrix} 1 & 2 \\ 4 & 3 \end{pmatrix} $$

Matrixinversion

Um die Inverse einer Matrix zu berechnen, verwenden Sie die Funktion inv().

Zum Beispiel, um die Inverse der Matrix M1 zu berechnen, tippen Sie inv(M1)

>> inv(M1)
Antwort =
-0.60000 0.80000
0.40000 -0.20000

Die Inverse der Matrix M1 ist eine Matrix, die, wenn sie mit M1 multipliziert wird, eine Identitätsmatrix ergibt. Eine Identitätsmatrix ist eine Matrix, deren Elemente auf der Hauptdiagonalen gleich 1 und ansonsten 0 sind. $$ M1 \cdot \text{inv} (M1) = \begin{pmatrix} 1 & 4 \\ 2 & 3 \end{pmatrix} \cdot \begin{pmatrix} -0.6 & 0.8 \\ 0.4 & -0.2 \end{pmatrix} = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} $$

Das charakteristische Polynom

Um das charakteristische Polynom einer quadratischen Matrix zu berechnen, können Sie die Funktion poly() verwenden.

>> poly(M1)
Antwort =
1 -4 -5

 
 

Segnalami un errore, un refuso o un suggerimento per migliorare gli appunti

FacebookTwitterLinkedinLinkedin

Matrizen in Matlab

Häufig gestellte Fragen