红宝石 |矩阵奇异?()函数
单数?()是 Ruby 中的一个内置方法,它返回一个布尔值。如果它是奇异矩阵,则返回 true,否则返回 false。如果使用方阵以外的任何东西,它会返回错误。
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.
示例 1 :
# 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?()
输出:
true
示例 2 :
# 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?()
输出:
false