How to calculate the sum of the columns in a matrix