Calculate matrix.