红宝石 |矩阵行列式()函数
行列式 ()是 Ruby 中的一个内置方法,它返回给定矩阵的行列式。
Syntax: mat1.det()
Parameters: The function does not accepts any parameter.
Return Value: It returns the determinant of the given matrix.
示例 1 :
# Ruby program for determinant() 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.determinant()
输出:
-7+10i
示例 2 :
# Ruby program for determinant() 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.determinant()
输出:
-6