Completed problem 22 and 49 in MATLAB