Open In App

Ruby | Matrix hermitian?() function

Last Updated : 12 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report
The hermitian?() is an inbuilt method in Ruby returns a boolean value. It returns true if the matrix is hermitian, else it returns false. It throws an error if anything other than a square matrix is checked for.
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.
Example 1: Ruby
# 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?()
Output:
false
Example 2: Ruby
# 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?()
Output:
true

Similar Reads