adding matrix function