How to accelerate matrix operations(multiplication, add, inverse) in a for loop?