matrix  calculation