Open In App

Ruby | Matrix upper_triangular?() function

Last Updated : 07 Jan, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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 is a lower-triangular matrix, else it returns false.

Example 1:




# Ruby program for upper_triangular?() method in Matrix
   
# Include matrix 
require "matrix"
   
# Initialize a matrix 
mat1 = Matrix[[1, 21], [31, 18]]  
   
# Prints if upper_triangular or not 
puts  mat1.upper_triangular?()


Output:

false

Example 2:




# Ruby program for upper_triangular?() method in Matrix
   
# Include matrix 
require "matrix"
   
# Initialize a matrix 
mat1 = Matrix[[31, 18, 19], [0, 3, 2],  [0, 0, 1]]
   
# Prints if upper_triangular or not 
puts  mat1.upper_triangular?()


Output:

true

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads