A sample cost function implementation to be used by advanced optimization algorithms.