implemantation of double*matrix calculation