stdlib/matrix.rb
#
# Returns the Laplace expansion along given row or column.
#
#    Matrix[[7,6], [3,9]].laplace_expansion(column: 1)
#     => 45
#
#    Matrix[[Vector[1, 0], Vector[0, 1]], [2, 3]].laplace_expansion(row: 0)
#     => Vector[3, -2]
#
#
Returns the Laplace expansion along given row or column.


Returns the Laplace expansion along given row or column .
def laplace_expansion(row: nil, column: nil)
    num = row || column
    if !num || (row && column)
      raise ArgumentError, "exactly one the row or column arguments must be specified"
    end
    Matrix.Raise ErrDimensionMismatch unless square?
    raise RuntimeError, "laplace_expansion of empty matrix is not defined" if empty?
    unless 0 <= num && num < row_count
      raise ArgumentError, "invalid num (#{num.inspect} for 0..#{row_count - 1})"
    end
    send(row ? :row : :column, num).map.with_index { |e, k|
      e * cofactor(*(row ? [num, k] : [k,num]))
    }.inject(:+)
  end
def laplace_expansion ( row : nil , column : nil ) num = row || column if ! num || ( row && column ) raise ArgumentError , "exactly one the row or column arguments must be specified" end Matrix . Raise ErrDimensionMismatch unless square? raise RuntimeError , "laplace_expansion of empty matrix is not defined" if empty? unless 0 <= num && num < row_count raise ArgumentError , "invalid num (#{num.inspect} for 0..#{row_count - 1})" end send ( row ? :row : :column , num ) . map . with_index { | e , k | e * cofactor ( * ( row ? [ num , k ] : [ k , num ] ) ) } . inject ( :+ ) end
Returns the Laplace expansion along given row or column.
Returns the Laplace expansion along given row or column .
row
<not_specific>
column
<not_specific>