multi-var cost function