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