Calculations on matrices