红宝石 |矩阵 cofactor_expansion()函数
cofactor_expansion()是 Ruby 中的一个内置方法,它沿给定行或列返回给定矩阵的 cofactor_expansion。换句话说,它返回 拉普拉斯展开。
Syntax: mat1.cofactor_expansion(row: num or col:num)
Parameters: The function accepts one mandatory parameter row or column whose cofactor_expansion is returned.
Return Value: It returns the cofactor-expansion of the given matrix along the given row or column.
示例 1 :
Ruby
# Ruby program for cofactor_expansion() method in Matrix
# Include matrix
require "matrix"
# Initialize a matrix
mat1 = Matrix[[1, 21], [31, 18]]
# Prints the value of mat1.cofactor_expansion
# first row
puts mat1.cofactor_expansion(row:1)
Ruby
# Ruby program for cofactor_expansion() method in Matrix
# Include matrix
require "matrix"
# Initialize a matrix
mat1 = Matrix[[13, 1, 5], [12, 1, 5], [11, 2, 5]]
# Prints the value of mat1.cofactor_expansion
# first row
puts mat1.cofactor_expansion(column:0)
输出:
-633
示例 2 :
红宝石
# Ruby program for cofactor_expansion() method in Matrix
# Include matrix
require "matrix"
# Initialize a matrix
mat1 = Matrix[[13, 1, 5], [12, 1, 5], [11, 2, 5]]
# Prints the value of mat1.cofactor_expansion
# first row
puts mat1.cofactor_expansion(column:0)
输出:
-5