stdlib/matrix.rb
#
# Returns the submatrix obtained by deleting the specified row and column.
#
#   Matrix.diagonal(9, 5, -3, 4).first_minor(1, 2)
#     => 9 0 0
#        0 0 0
#        0 0 4
#
Returns the submatrix obtained by deleting the specified row and column.
Returns the submatrix obtained by deleting the specified row and column .
def first_minor(row, column)
    raise RuntimeError, "first_minor of empty matrix is not defined" if empty?
    unless 0 <= row && row < row_count
      raise ArgumentError, "invalid row (#{row.inspect} for 0..#{row_count - 1})"
    end
    unless 0 <= column && column < column_count
      raise ArgumentError, "invalid column (#{column.inspect} for 0..#{column_count - 1})"
    end
    arrays = to_a
    arrays.delete_at(row)
    arrays.each do |array|
      array.delete_at(column)
    end
    new_matrix arrays, column_count - 1
  end
def first_minor ( row , column ) raise RuntimeError , "first_minor of empty matrix is not defined" if empty? unless 0 <= row && row < row_count raise ArgumentError , "invalid row (#{row.inspect} for 0..#{row_count - 1})" end unless 0 <= column && column < column_count raise ArgumentError , "invalid column (#{column.inspect} for 0..#{column_count - 1})" end arrays = to_a arrays . delete_at ( row ) arrays . each do | array | array . delete_at ( column ) end new_matrix arrays , column_count - 1 end
Returns the submatrix obtained by deleting the specified row and column.
Returns the submatrix obtained by deleting the specified row and column .
row
<not_specific>
column
<not_specific>