Open In App

Ruby | Matrix hermitian?() function

Improve
Improve
Like Article
Like
Save
Share
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 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

Last Updated : 07 Jan, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads