computed cost function