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