adding matrix to document