Ruby | Matrix I() function Last Updated : 07 Jan, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 # Include matrix require "matrix" # Initialize a matrix # using I method mat1 = Matrix.I(2) # Print the matrix puts mat1 Output: Matrix[[1, 0], [0, 1]] Example 2: Ruby # Ruby program for I() method in Matrix # Include matrix require "matrix" # Initialize a matrix # using I method mat1 = Matrix.I(3) # Print the matrix puts mat1 Output: Matrix[[1, 0, 0], [0, 1, 0], [0, 0, 1]] Comment More infoAdvertise with us Next Article Ruby | Matrix inv() function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Matrix-class Similar Reads 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 imag() function 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( 1 min read Ruby | Matrix t() function The t() is an inbuilt method in Ruby returns the transpose of the matrix. Syntax: mat1.t() Parameters: The function needs the matrix to be transposed. Return Value: It returns the transposed matrix. Example 1: Ruby # Ruby program for t() method in Matrix # Include matrix require "matrix" # 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 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 | Matrix tr() function The tr() is an inbuilt method in Ruby returns the trace i.e., sum of diagonal elements of the matrix. Syntax: mat1.tr() Parameters: The function needs the matrix whose trace is to be returned. Return Value: It returns the trace. Example 1: Ruby # Ruby program for tr() method in Matrix # Include matr 1 min read Like