Matrix inversion by modified method of Gram-Schmidt