Use linearSolve instead of matrix inversion