红宝石 |矩阵酉?()函数
unitary?()是 Ruby 中的一个内置方法,它返回一个布尔值。如果是酉矩阵则返回真,否则返回假。如果使用酉矩阵以外的任何东西,它会返回错误。
Syntax: mat1.unitary?()
Parameters: The function needs the matrix to be checked for unitary matrix or not.
Return Value: It returns true if it is a unitary matrix, else it returns false.
示例 1 :
# Ruby program for unitary?() method in Matrix
# Include matrix
require "matrix"
# Initialize a matrix
mat1 = Matrix[[1, 0], [0, Complex(0,1)]]
# Prints if unitary? or not
puts mat1.unitary?()
输出:
true
示例 2 :
# Ruby program for unitary?() method in Matrix
# Include matrix
require "matrix"
# Initialize a matrix
mat1 = Matrix[[0, -6, 4], [-6, 0, 7], [4, 7, 0]]
# Prints if unitary? or not
puts mat1.unitary?()
输出:
false