class AlgebraUtils {

    public static RealVector flattenMatrixByColumns(RealMatrix matrix) {
        int m = matrix.getColumnDimension(); // returns the width of the matrix, i.e. number of columns.
        int n = matrix.getRowDimension(); // returns the height of the matrix, i.e. number of rows.
        RealVector vector = matrix.getColumnVector(0);
        for (int i = 1; i < m; i++) {
            vector = vector.append(matrix.getColumnVector(i));
        }
        return vector;
    }

}