code for matrix method