matrix multiplication and addition integrated with main code