Ruby | Matrix singular?() function Last Updated : 06 Aug, 2024 Comments Improve Suggest changes Like Article Like Report The singular?() is an inbuilt method in Ruby returns a boolean value. It returns true if it is a singular matrix, else it returns false. It returns error if anything other than square matrix is used. Syntax: mat1.singular?() Parameters: The function needs the matrix to be checked for singular matrix or not. Return Value: It returns true if it is a singular matrix, else it returns false.Example 1: Ruby # Ruby program for singular?() method in Matrix # Include matrix require "matrix" # Initialize a matrix mat1 = Matrix[[3, 12], [2, 8]] # Prints if singular? or not puts mat1.singular?() Output: trueExample 2: Ruby # Ruby program for singular?() method in Matrix # Include matrix require "matrix" # Initialize a matrix mat1 = Matrix[[1, 0], [0, 1]] # Prints if singular? or not puts mat1.singular?() Output: false Comment More infoAdvertise with us Next Article Ruby | Matrix singular?() function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Matrix-class Similar Reads Ruby | Matrix square?() function The square?() is an inbuilt method in Ruby returns a boolean value. It returns true if it is a square matrix, else it returns false. Syntax: mat1.square?() Parameters: The function needs the matrix to be checked for square matrix or not. Return Value: It returns true if it is a square matrix, else i 1 min read Ruby | Matrix scalar() function The scalar() is an inbuilt method in Ruby returns an N x N diagonal matrix where each diagonal element is value. Syntax: mat1.scalar(N, value) Parameters: The function accepts twos mandatory parameters N and value where N is the size of the Identity matrix and value is the value to be assigned to th 1 min read Ruby | Matrix lower_triangular? function The lower_triangular?() is an inbuilt method in Ruby returns a boolean value. It returns true if it is a lower-triangular matrix, else it returns false. Syntax: mat1.lower_triangular?() Parameters: The function needs the matrix to be checked for lower-triangular. Return Value: It returns true if it 1 min read Ruby | Matrix upper_triangular?() function The upper_triangular?() is an inbuilt method in Ruby returns a boolean value. It returns true if it is a lower-triangular matrix, else it returns false. Syntax: mat1.upper_triangular?() Parameters: The function needs the matrix to be checked for lower-triangular. Return Value: It returns true if it 1 min read Ruby | Matrix tr() function The tr() is an inbuilt method in Ruby returns the trace i.e., sum of diagonal elements of the matrix. Syntax: mat1.tr() Parameters: The function needs the matrix whose trace is to be returned. Return Value: It returns the trace. Example 1: Ruby # Ruby program for tr() method in Matrix # Include matr 1 min read Like