红宝石 |矩阵 inv()函数
inv()是 Ruby 中的一个内置方法,它返回给定矩阵的逆矩阵。
Syntax: mat1.inv()
Parameters: The function does not takes any parameter.
Return Value: It returns the inverse of a matrix.
示例 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()
输出:
Matrix[[-313/24692-459/24692i, 777/24692+35/24692i], [1147/24692+155/74076i, -101/74076-227/74076i]]
示例 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()
输出:
Matrix[[1/3, -1/3], [-1/12, -1/24]]