红宝石 |矩阵对称?()函数
symmetric?()是 Ruby 中的一个内置方法,它返回一个布尔值。如果矩阵是对称的,则返回 true,否则返回 false。如果检查方阵以外的任何内容,则会引发错误。
Syntax: mat1.symmetric?()
Parameters: The function needs a matrix whose symmetric is to be checked for.
Return Value: It returns true if the matrix is symmetric, else it returns false.
示例 1 :
# Ruby program for symmetric?() method in Matrix
# Include matrix
require "matrix"
# Initialize a matrix
mat1 = Matrix[[1, 21], [31, 18]]
# Prints the value of mat1.symmetric?()
puts mat1.symmetric?()
输出:
true
示例 2 :
# Ruby program for symmetric?() method in Matrix
# Include matrix
require "matrix"
# Initialize a matrix
mat1 = Matrix[[1, 1, 5], [1, 1, 5], [1, 2, 5]]
# Prints the value of mat1.symmetric?()
puts mat1.symmetric?()
输出:
false