Updated code to accept a Matrix, and to use the solve() function, as
opposed to the mean() function