Last Updated 10/21/2022

Sage Essentials
Section 7: Matrix Manipulations

Special Matrices

SageMath has convenient ways to define common special matrices such as diagonal, identity, and zero matrices.

Example 2

To define the diagonal matrix  A=[ 2 0 0 0 0 1 0 0 0 0 5 0 0 0 0 1 ] , we list the diagonal elements with the diagonal_matrix command.

 

 

To define an identity matrix, we use the identity_matrix command. For example, the 4×4 identity matrix  I 4 =[ 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 ] is defined by identity_matrix(4).

 

Alternatively, an identity matrix is a diagonal matrix. For example, I 4  can be defined as a 4×4 diagonal matrix with 1 as the diagonal elements.

 

Likewise, we can define the m×n zero matrices by the zero_matrix(m,n)command.

Try this!

Define the 3×4 zero matrix.

 


← Previous Example Next Example →