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:
require "matrix"
mat1 = Matrix[[ 1 , 21 ], [ 31 , 18 ]]
puts mat1.hermitian?()
|
Output:
false
Example 2:
require "matrix"
mat1 = Matrix[[ 2 , Complex( 2 , 1 ), 4 ], [Complex( 2 , - 1 ),
3 , Complex( 0 , 1 )], [ 4 , Complex( 0 ,- 1 ), 1 ]]
puts mat1.hermitian?()
|
Output:
true
Last Updated :
07 Jan, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...