Open In App

Ruby | Matrix minor() function

Improve
Improve
Like Article
Like
Save
Share
Report

The minor() is an inbuilt method in Ruby returns a section of the matrix. It either returns a matrix by taking the starting row, end row, start column, end column or by taking the range of rows and columns.

Syntax: mat1.minor(start_row, end_row, start_col, end_col) or mat1.minor(row1..row2, col1..col2)

Parameters: The function takes parameter in two ways, either it takes starting row, ending row, starting column or the ending column, or it takes the range of rows and columns.

Return Value: It returns the section of a matrix.

Example 1:




#Ruby program for minor() method in Matrix
  
#Include matrix
require "matrix"
  
#Initialize a matrix
    mat1
    = Matrix[[ 1, 0, 0 ], [ 2, 3, 0 ], [ 31, 18, 19 ]]
  
#Prints the section of matrix
      puts mat1.minor(1, 2, 0, 2)


Output:

Matrix[[2, 3], [31, 18]]

Example 2:




#Ruby program for minor() method in Matrix
  
#Include matrix
require "matrix"
  
#Initialize a matrix
    mat1
    = Matrix[[ 1, 0, 0 ], [ 2, 3, 0 ], [ 31, 18, 19 ]]
  
#Prints the section of matrix
      puts mat1.minor(1..2, 0..2)


Output:

Matrix[[2, 3, 0], [31, 18, 19]]

Last Updated : 07 Jan, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads