hw 2, ex 3 - compute cost/gradient