Ruby | Vector to_matrix() function Last Updated : 07 Jan, 2020 Comments Improve Suggest changes Like Article Like Report The to_matrix() is an inbuilt method in Ruby returns the matrix of single column with elements of vector. Syntax: vec1.to_matrix() Parameters: The function accepts no parameter Return Value: It returns the matrix of single column with elements of vector Example 1: Ruby # Ruby program for to_matrix() method in Vector # Include matrix require "matrix" # Initialize the vector vec1 = Vector[1, 2, 3] # Prints the matrix with single column puts vec1.to_matrix() Output: Matrix[[1], [2], [3]] Example 2: Ruby # Ruby program for to_matrix() method in Vector # Include matrix require "matrix" # Initialize the vector vec1 = Vector[1, 1] # Prints the matrix with single column puts vec1.to_matrix() Output: Matrix[[1], [1]] Comment More infoAdvertise with us Next Article Ruby | Vector to_matrix() function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Vector-class Similar Reads Ruby | Matrix row_vectors() function The row_vectors() is an inbuilt method in Ruby returns vectors which represents each row in the matrix. Syntax: mat1.row_vectors() Parameters: The function does not takes any mandatory parameter. Return Value: It returns vectors representing the rows. Example 1: Ruby # Ruby program for row_vectors() 1 min read Ruby | Matrix to_s() function The to_s() is an inbuilt method in Ruby returns a string containing the matrix as the object. Syntax: mat1.to_s() Parameters: The function needs the matrix whose string object is to be returned. Return Value: It returns a string or self. Example 1: Ruby # Ruby program for to_s() method in Matrix # I 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 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 | Vector r() function The r() is an inbuilt method in Ruby returns the Pythagorean distance of the vector. Syntax: vec1.r() Parameters: The function accepts no parameter Return Value: It Pythagorean distance of the vector Example 1: Ruby # Ruby program for r() method in Vector # Include matrix require "matrix" 1 min read Like