Solution for matrix problem.