Ruby 矩阵 det()函数
det() 是Ruby中一个内置的方法,用于返回给定矩阵的行列式。
语法 :mat1.det()
参数 :该函数不接受任何参数。
返回值 : 它返回给定矩阵的行列式。
例子 1 :
# Ruby program for det() method in Matrix
# Include matrix
require "matrix"
# Initialize a matrix
mat1 = Matrix[[1, Complex(2, 1)], [Complex(8, -9), 18]]
# prints the determinant
puts mat1.det()
输出:
-7+10i
例2 :
# Ruby program for det() method in Matrix
# Include matrix
require "matrix"
# Initialize a matrix
mat1 = Matrix[[1, 1, 5], [4, 1, 5], [11, 2, 12]]
# prints the determinant
puts mat1.det()
输出:
-6