Ruby | Matrix diagonal() function Last Updated : 12 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The diagonal() is an inbuilt method in Ruby returns true if the given matrix is diagonal, else it returns false. A diagonal matrix is a matrix in which the entries outside the main diagonal are all zero. Syntax: mat1.diagonal() Parameters: The function does not accepts any parameter. Return Value: It returns true if the given matrix is diagonal, else it returns false.Example 1: Ruby # Ruby program for diagonal() method in Matrix # Include matrix require "matrix" # Initialize a matrix mat1 = Matrix[[1, 0], [0, 2]] # prints if diagonal matrix or not puts mat1.diagonal() Output: trueExample 2: Ruby # Ruby program for diagonal() method in Matrix # Include matrix require "matrix" # Initialize a matrix mat1 = Matrix[[1, 1, 5], [4, 1, 5], [11, 2, 12]] # prints the result puts mat1.diagonal() Output: false Comment More infoAdvertise with us Next Article Ruby | Matrix column() function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Matrix-class Similar Reads Ruby | Matrix eigen() function The eigen() is an inbuilt method in Ruby returns the Eigensystem of the matrix. Syntax: mat1.eigen() Parameters: The function does not accepts any parameter. Return Value: It returns the Eigensystem of the matrix. Example 1: Ruby # Ruby program for eigen() method in Matrix # Include matrix require 1 min read Ruby | Matrix conj() function The conj() is an inbuilt method in Ruby returns the conjugate matrix. Syntax: mat1.conj() Parameters: The function does not accepts any parameter. Return Value: It returns the conjugate matrix. Example 1: Ruby # Ruby program for conj() method in Matrix # Include matrix require "matrix" # I 1 min read Ruby | Matrix clone() function The clone() is an inbuilt method in Ruby returns a clone of the given matrix such that the contents are not referenced by identical objects. Syntax: mat1.clone() Parameters: The function needs a matrix whose clone is to returned. Return Value: It returns the clone matrix. Example 1: Ruby # Ruby prog 1 min read Ruby | Matrix det() function The det() is an inbuilt method in Ruby returns the determinant of the given matrix Syntax: mat1.det() Parameters: The function does not accepts any parameter. Return Value: It returns the determinant of the given matrix. Example 1: Ruby # Ruby program for det() method in Matrix # Include matrix requ 1 min read Ruby | Matrix column() function The column() is an inbuilt method in Ruby returns a vector that has all the elements in the column number col_num. Syntax: mat1.column(col_num) Parameters: The function accepts a parameter col_num which is the column number. Return Value: It returns a vector which has all the elements of column col_ 1 min read Ruby | Matrix determinant() function The determinant () is an inbuilt method in Ruby returns the determinant of the given matrix. Syntax: mat1.det() Parameters: The function does not accepts any parameter. Return Value: It returns the determinant of the given matrix. Example 1: Ruby # Ruby program for determinant() method in Matrix # I 1 min read Like