Ruby | Matrix component() function

The component() is an inbuilt method in Ruby returns the element present at the intersection of i-th row and j-th column.

Syntax: mat1.component(i, j)

Parameters: The function accepts two parameters i and j which signifies the row_number and column_number.

Return Value: It returns the element at mat[i][j].

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby program for component() method in Matrix
  
# Include matrix 
require "matrix"
  
# Initialize a matrix 
mat1 =  Matrix[[1, 21], [31, 18]]       
  
# prints the element at 1, 1
puts  mat1.component(1, 1)

chevron_right


Output:

18

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby program for component() method in Matrix
   
# Include matrix 
require "matrix"
   
# Initialize a matrix 
mat1 =  Matrix[[13, 1, 5], [12, 1, 5], [11, 2, 5]]    
   
# prints the element at 0, 1
puts  mat1.component(0, 1)

chevron_right


Output:

1
My Personal Notes arrow_drop_up

Recommended Posts:

    Article Tags :

    Be the First to upvote.


    Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.