Identitätsmatrizen in Matlab
In dieser Lektion zeige ich Ihnen, wie Sie in Matlab eine Identitätsmatrix erstellen können.
Was versteht man unter einer Identitätsmatrix? Eine Identitätsmatrix, auch Einheitsmatrix genannt, ist eine quadratische Matrix, deren Hauptdiagonalelemente 1 und alle anderen Elemente 0 sind. Hier ein Beispiel einer 3x3 Identitätsmatrix: $$ I = \begin{pmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{pmatrix} $$
Um in Matlab eine Identitätsmatrix zu generieren, nutzen Sie die Funktion eye(n).
eye(n)
Hierbei steht 'n' für die Anzahl der Zeilen beziehungsweise Spalten der Matrix.
Werfen wir einen Blick auf ein praktisches Beispiel.
Um eine 2x2 Identitätsmatrix zu erzeugen, tippen Sie einfach eye(2).
>> eye(2)
Dieser Befehl erstellt eine 2x2 Identitätsmatrix.
ans =
1 0
0 1
Um eine 3x3 Identitätsmatrix zu erzeugen, tippen Sie eye(3).
>> eye(3)
Das Resultat ist eine 3x3 Identitätsmatrix.
ans =
1 0 0
0 1 0
0 0 1
Mit dieser Methode können Sie eine Identitätsmatrix beliebiger Größe definieren.
Zudem erlaubt die Funktion eye(m,n) mit zwei Parametern das Erstellen einer rechteckigen Matrix, die als quadratische Teilmatrix eine Identitätsmatrix beinhaltet.
eye(m,n)
Hierbei gibt 'm' die Anzahl der Zeilen und 'n' die Anzahl der Spalten der rechteckigen Matrix an.
Beispiel: Um eine 2x3 Matrix mit einer eingebetteten Identitätsteilmatrix zu erstellen, geben Sie eye(2,3) ein.
>> eye(2,3)
Matlab erzeugt daraufhin eine rechteckige Matrix mit einer eingebetteten Identitätsmatrix.
ans =
1 0 0
0 1 0