Implementede exercise 3 in Matlab