
How to make an identity matrix in Octave
In this lesson I'll explain how to make an identity matrix in Octave
What is an identity matrix? It is a square matrix composed of the same number of rows and columns with unitary values (1) in the main diagonal and zero (0) elsewhere. For example $$ I = \begin{pmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{pmatrix} $$
I'll give you a practical example.
To create an identity matrix of dimension 2 (two rows and two columns) use the eye() function.
>> eye(2)
The result is an identity matrix with two rows and two columns
ans =
Diagonal Matrix
1 0
0 1
If you want to create an identity matrix with three rows and three columns type eye(3)
>> eye(3)
The result is an identity matrix of dimension 3
ans =
Diagonal Matrix
1 0 0
0 1 0
0 0 1
The eye () function allows you to define an identity matrix of any size.
You can also use the eye(m, n) function to create a rectangular matrix with m rows and n columns that includes an identity submatrix.
For example, type eye(2,3) to create a 2x3 matrix with an identity matrix inside it
>> eye(2,3)
The result is a 2x3 rectangular matrix with a 2x2 identity matrix as a square submatrix.
ans =
Diagonal Matrix
1 0 0
0 1 0