Open In App

Ruby | Matrix to_matrix() function

Last Updated : 07 Jan, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

The to_matrix() is an inbuilt method in Ruby returns a matrix which is self only.

Syntax: mat1.to_matrix()

Parameters: The function needs the matrix which is to be returned.

Return Value: It returns an matrix, or self.

Example 1:




# Ruby program for to_matrix() method in Matrix
   
# Include matrix 
require "matrix"
   
# Initialize a matrix 
mat1 = Matrix[[3, 12], [2, 8]]  
   
# Prints the to_matrix matrix
puts  mat1.to_matrix()


Output:

Matrix[[3, 12], [2, 8]]

Example 2:




# Ruby program for to_matrix() method in Matrix
   
# Include matrix 
require "matrix"
   
# Initialize a matrix 
mat1 = Matrix[[1, 0], [6, 1], [1, 2]]  
   
# Prints the to_matrix matrix
puts  mat1.to_matrix()


Output:

Matrix[[1, 0], [6, 1], [1, 2]]

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads