Implemented basic matrix function