Calculates matrix operations