📜  红宝石 |矩阵**法

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

红宝石 |矩阵**法

**是 Ruby 中的内置方法,在矩阵与自身相乘 N 次后返回矩阵。它返回矩阵求幂值。

示例 1

# Ruby program for ** method in Matrix
# Include matrix 
require "matrix"
  
# Initialize a matrix 
mat = Matrix[[12,41], [61,81]] 
  
# Prints the matrix value after 
# multiplying it 3 times with self 
puts  mat ** 3

输出

Matrix[[264333, 417298], [620858, 966615]]

示例 2

# Ruby program for ** method in Matrix
# Include matrix 
require "matrix"
   
# Initialize a matrix 
mat = Matrix[[1, 2, 6], [3, 4, 8], [12, 1, 3]] 
   
# Prints the matrix value after 
# multiplying it 2 times with self 
puts  mat ** 2

输出

Matrix[[79, 16, 40], [111, 30, 74], [51, 31, 89]]