📜  红宝石 |矩阵划分/方法

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

红宝石 |矩阵划分/方法

/是 Ruby 中的一个内置方法,它返回一个矩阵,该矩阵由两个矩阵 mat1 和 mat2 相除。在这里,除法意味着乘以逆。

示例 1

Ruby
# 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


Ruby
# 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


输出

Matrix[[1/1, 0/1, 0/1], [0/1, 1/1, 0/1], [0/1, 0/1, 1/1]]

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

输出

Matrix[[623/468, -5/468], [-155/234, 239/234]]