diff --git a/lib/matrix.rb b/lib/matrix.rb index 76bec92..390aaf6 100644 --- a/lib/matrix.rb +++ b/lib/matrix.rb @@ -60,6 +60,7 @@ end # * #minor(*param) # * #first_minor(row, column) # * #cofactor(row, column) +# * #column_merge(*matrices) # # Properties of a matrix: # * #diagonal? @@ -636,6 +637,21 @@ class Matrix det_of_minor * (-1) ** (row + column) end + # + # Merge matrices between columns. + # + # Matrix[[1, 2], [3, 4]].column_merge(Matrix[[5, 6]]) + # => 1 2 + # 3 4 + # 5 6 + # + def column_merge(*matrices) + if matrices.any?{|m| m.column_size != column_size } + raise ErrDimensionMismatch, "all matrices should have same column size" + end + new_matrix [self, *matrices].map(&:to_a).flatten(1) + end + #-- # TESTING -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #++