红宝石 |矩阵 rank()函数
rank()是 Ruby 中的一个内置方法,它返回给定矩阵的秩。由于浮点精度,浮点值可以产生巨大的结果
Syntax: mat1.rank()
Parameters: The function does not accepts any parameter.
Return Value: It returns the rank of the current matrix.
示例 1 :
#Ruby program for rank() method in Matrix
#Include matrix
require "matrix"
#Initialize a matrix
mat1
= Matrix[[ 1, 21 ], [ 31, 18 ]]
#Prints the rank
puts mat1.rank()
输出:
2
示例 2 :
#Ruby program for rank() method in Matrix
#Include matrix
require "matrix"
#Initialize a matrix
mat1
= Matrix[[ 1, 0 ], [ 0, 1 ]]
#Prints the rank
puts mat1.rank()
输出:
2