Ruby | Matrix hstack() function Last Updated : 07 Jan, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report The hstack() is an inbuilt method in Ruby returns a new matrix resulting by stacking horizontally the receiver with the given matrices. It requires a matrix which is stacked upon horizontally. Syntax: mat1.hstack(mat2) Parameters: The function needs a matrix which is to be stacked horizontally. Return Value: It returns resultant matrix after stacking is done. Example 1: CPP #Ruby program for hstack() method in Matrix #Include matrix require "matrix" #Initialize a matrix mat1 = Matrix[[ 1, 21 ], [ 31, 18 ]] mat2 = Matrix[[ 4, 6 ], [ 3, 9 ]] #prints the resultant matrix puts mat1.hstack(mat2) Output: Matrix[[1, 21, 4, 6], [31, 18, 3, 9]] Example 2: CPP #Ruby program for hstack() method in Matrix #Include matrix require "matrix" #Initialize a matrix mat1 = Matrix[[ 3, 5, 9 ], [ 10, 19, 123 ]] mat2 = Matrix[[ 12, 12 ], [ 19, 18 ]] #prints the resultant matrix puts mat1.hstack(mat2) Output: Matrix[[3, 5, 9, 12, 12], [10, 19, 123, 19, 18]] Comment More infoAdvertise with us Next Article Ruby | Matrix imag() function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Matrix-class Similar Reads 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 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 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 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 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 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 Like