Matlab code for week 3