Calculates the scalar multiplication of a matrix.