红宝石 |矩阵次要()函数
minor()是 Ruby 中的一个内置方法,它返回矩阵的一部分。它通过获取起始行、结束行、开始列、结束列或获取行和列的范围来返回矩阵。
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.
示例 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)
输出:
Matrix[[2, 3], [31, 18]]
示例 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)
输出:
Matrix[[2, 3, 0], [31, 18, 19]]