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 it returns false.
Example 1:
require "matrix"
mat1 = Matrix[[ 3 , 12 ], [ 2 , 8 ]]
puts mat1.square?()
|
Output:
true
Example 2:
require "matrix"
mat1 = Matrix[[ 1 , 0 ], [ 0 , 1 ], [ 1 , 2 ]]
puts mat1.square?()
|
Output:
false
Last Updated :
07 Jan, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...