Skip to content
Related Articles

Related Articles

Ruby | Matrix hermitian?() function
  • Last Updated : 07 Jan, 2020

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 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 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

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :