Ruby | Vector component() function
The component() is an inbuilt method in Ruby returns element at index i in the vector. Indexing starts from zero.
Syntax: vec1.component(i)
Parameters: The function accepts a single parameter
Return Value: It returns element at index i in the vector
Example 1:
#Ruby program for component() method in Vector #Include matrix require "matrix" #Initialize the vector vec1 = Vector[1, 2] i = 1 #Prints element at index i puts vec1.component(i) |
chevron_right
filter_none
Output:
2
Example 2:
#Ruby program for component() method in Vector #Include matrix require "matrix" #Initialize the vector vec1 = Vector[1, 2, 3] i = 2 #Prints element at index i puts vec1.component(i) |
chevron_right
filter_none
Output:
3
Recommended Posts:
- Ruby | Matrix component() function
- Ruby | Vector zero?() function
- Ruby | Vector r() function
- Ruby | Vector zero() function
- Ruby | Vector eql?() function
- Ruby | Vector angle_with() function
- Ruby | Vector normalize() function
- Ruby | Vector independent? function
- Ruby | Vector norm() function
- Ruby | Vector cross_product() function
- Ruby | Vector inner_product() function
- Ruby | Vector hash() function
- Ruby | Vector covector() function
- Ruby | Vector to_matrix() function
- Ruby | Vector to_a() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

