compute cost for multiple variables