lettura simple

Zero matrix in Octave

In this lesson I'll explain how to create a zero matrix (null matrix) in Octave using zeros() function.

What is a zero matrix? It is a matrix with all elements equal to zero. It is also called the null matrix. Here is an example of a zero matrix $$ M = \begin{pmatrix} 0 & 0 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & 0 \end{pmatrix} $$

I'll give you a practical example

Type zeros(3) to create a null square matrix with 3 rows and 3 columns

>> zeros(3)
ans =
0 0 0
0 0 0
0 0 0

Type zeros(2,3) to create a null rectangular matrix with 2 rows and 3 columns

The first parameter is the number of rows while the second is the number of columns.

>> zeros(2,3)
ans =
0 0 0
0 0 0

Type zeros(3,2) to create a null rectangular matrix with 3 rows and 2 columns

>> zeros(3,2)
ans =
0 0
0 0
0 0

This way you can quickly create any zero matrix.

Note. Alternatively, you can also manually define a null matrix by entering all zeros. However, the process is much longer. Especially if the matrix is very large.
a zero matrix

 




Report a mistake or post a question




FacebookTwitterLinkedinLinkedin