Ruby | Matrix division / method
The / is an inbuilt method in Ruby returns a matrix which has the division of two matrix mat1 and mat2. Here, division means multiplication with the inverse.
Syntax: mat1 – mat2
Parameters: The function need two matrix mat1 and mat2 which are to be divided.
Return Value: It returns the resultant matrix after divided.
Example 1:
# Ruby program for / method in Matrix # Include matrix require "matrix" # Initialize a matrix mat1 = Matrix[[1, 2, 6], [3, 4, 8], [12, 1, 3]] mat2 = Matrix[[1, 2, 6], [3, 4, 8], [12, 1, 3]] # Prints the value of mat1/mat2 puts mat1 / mat2 |
chevron_right
filter_none
Output:
Matrix[[1/1, 0/1, 0/1], [0/1, 1/1, 0/1], [0/1, 0/1, 1/1]]
Example 2:
# Ruby program for / method in Matrix # Include matrix require "matrix" # Initialize a matrix mat1 = Matrix[[1, 21], [31, 18]] mat2 = Matrix[[1, 16], [31, 28]] # Prints the value of mat1/mat2 puts mat1 / mat2 |
chevron_right
filter_none
Output:
Matrix[[623/468, -5/468], [-155/234, 239/234]]
Recommended Posts:
- Ruby | Matrix ** method
- Ruby | Matrix == method
- Ruby | Matrix [] method
- Ruby | Matrix - method
- Ruby | Matrix + method
- Ruby | Matrix eql? function
- Ruby | Matrix det() function
- Ruby | Matrix row() function
- Ruby | Matrix tr() function
- Ruby | Matrix zero?() function
- Ruby | Matrix t() function
- Ruby | Matrix I() function
- Ruby | Matrix zero() function
- Ruby | Matrix lup() function
- Ruby | Matrix inv() 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.



