Ruby 矩阵cofactor_expansion()函数
cofactor_expansion() 是Ruby中的一个内置方法,用于返回给定矩阵沿给定行或列的cofactor_expansion。换句话说,它返回 **** Laplace扩展。
语法 :mat1.cofactor_expansion(row: num or col:num)
参数 :该函数接受一个强制性参数row或column,其cofactor_expansion被返回。
返回值 :它返回给定矩阵沿给定行或列的cofactor-expansion。
例子 1 :
# 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)
输出:
-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