Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Ruby | Matrix rank() function

  • Last Updated : 07 Jan, 2020

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
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!