add ex4
Ex4 cost function