ex3 costFunction