Open In App

Ruby | Matrix rank() function

The rank() is an inbuilt method in Ruby returns the rank of the given matrix. The float values can yield enormous results due to float precision

Syntax: mat1.rank()



Parameters: The function does not accepts any parameter.

Return Value: It returns the rank of the current matrix.



Example 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()

Output:

2

Example 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()

Output:

2
Article Tags :