Adding a solution to problem 2a in matlab script