Ruby | Matrix inv() function
The inv() is an inbuilt method in Ruby returns the inverse of the given matrix.
Syntax: mat1.inv()
Parameters: The function does not takes any parameter.
Return Value: It returns the inverse of a matrix.
Example 1:
#Ruby program for inv() method in Matrix #Include matrix require "matrix" #Initialize a matrix mat1 = Matrix[[ Complex(1, 2), 21 ], [ 31, Complex(9, 12) ]] #prints the inv matrix puts mat1.inv() |
Output:
Matrix[[-313/24692-459/24692i, 777/24692+35/24692i], [1147/24692+155/74076i, -101/74076-227/74076i]]
Example 2:
#Ruby program for inv() method in Matrix #Include matrix require "matrix" #Initialize a matrix mat1 = Matrix[[ 1, -8 ], [ -2, -8 ]] #prints the inv matrix puts mat1.inv() |
Output:
Matrix[[1/3, -1/3], [-1/12, -1/24]]
Contact Us