Horje
Ruby | Matrix hermitian?() function

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



Reffered: https://www.geeksforgeeks.org


Ruby

Related
Ruby | Time hash function Ruby | Time hash function
Ruby | Matrix hash() function Ruby | Matrix hash() function
Ruby | Matrix first_minor() function Ruby | Matrix first_minor() function
Ruby | Time hour function Ruby | Time hour function
Ruby | Hash flatten() function Ruby | Hash flatten() function

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
8