Cost function for single variable.