Ruby | Matrix imag() function Last Updated : 07 Jan, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report The imag() is an inbuilt method in Ruby returns a matrix with only imaginary part in it. The other index are assigned to zero. Syntax: mat1.imag() Parameters: The function does not takes any parameter. Return Value: It returns a matrix with only imaginary part. Example 1: CPP #Ruby program for imag() method in Matrix #Include matrix require "matrix" #Initialize a matrix mat1 = Matrix[[ Complex(1, 2), 21 ], [ 31, Complex(9, 12) ]] #prints the imaginary part puts mat1.imag() Output: Matrix[[2, 0], [0, 12]] Example 2: CPP #Ruby program for imag() method in Matrix #Include matrix require "matrix" #Initialize a matrix mat1 = Matrix[[ Complex(19, 3), Complex(12, 3) ], [ Complex(7, 8), Complex(91, 2) ]] #prints the imaginary part puts mat1.imag() Output: Matrix[[3, 3], [8, 2]] Comment More infoAdvertise with us Next Article Ruby | Numeric imag() function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Matrix-class Similar Reads Ruby | Matrix I() function The I() is an inbuilt method in Ruby returns a Identity matrix of N X N size. Syntax: mat1.I(N) Parameters: The function accepts a mandatory parameter N which is the size of the Identity matrix. Return Value: It returns the Identity matrix. Example 1: Ruby # Ruby program for I() method in Matrix # I 1 min read Ruby | Matrix imaginary() function The imaginary() is an inbuilt method in Ruby returns a matrix with only imaginary part in it. The other index are assigned to zero. Syntax: mat1.imaginary() Parameters: The function does not takes any parameter. Return Value: It returns a matrix with only imaginary part. Example 1: CPP #Ruby program 1 min read Ruby | Matrix inv() function The inv() is an inbuilt method in Ruby returns the inverse of the given matrix. Syntax: mat1.inv() Parameters: The function does not takes any parameter. Return Value: It returns the inverse of a matrix. Example 1: CPP #Ruby program for inv() method in Matrix #Include matrix require "matrix 1 min read Ruby | Matrix hash() function The hash() is an inbuilt method in Ruby returns the hash-code of the matrix. Syntax: mat1.hash()Parameters: The function does not accepts any parameter.Return Value: It returns the hash-code of the matrix. Example 1:Â Â Ruby # Ruby program for hash() method in Matrix # Include matrix require "matrix" 1 min read Ruby | Numeric imag() function The imag() is an inbuilt method in Ruby returns the imag part of the given number. Syntax: num.imag() Parameters: The function needs a number whose imag part is to be returned. Return Value: It returns the imag part. Example 1: CPP # Ruby program for imag() # method in Numeric # Initialize a number 1 min read Ruby | Matrix lup() function The lup() is an inbuilt method in Ruby returns the LUP decomposition of the given matrix. Syntax: mat1.lup() Parameters: The function needs the matrix whose LUP decomposition is to be returned. Return Value: It returns the LUP decomposition of the matrix. Example 1: CPP #Ruby program for lup() metho 1 min read Like