📜  红宝石 |矩阵逆()函数

📅  最后修改于: 2022-05-13 01:54:47.318000             🧑  作者: Mango

红宝石 |矩阵逆()函数

inverse()是 Ruby 中的内置方法,返回给定矩阵的逆矩阵。

示例 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()

输出

Matrix[[-313/24692-459/24692i, 777/24692+35/24692i], [1147/24692+155/74076i, -101/74076-227/74076i]]

示例 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()

输出

Matrix[[1/3, -1/3], [-1/12, -1/24]]