The OptimProblem types of problem is somewhat difficult to set up and is inconvient to use for most of the cases. A $C^0$ is a continiouse function, a $C^1$ function is a smooth function, but a $C^2$ function is a function that is continuous, smooth and has second derivative. It is also called a twice differentiable function.

				
// An example multivariate function.
val f: RealScalarFunction = object : AbstractBivariateRealFunction() {
override fun evaluate(x: Double, y: Double): Double {
return x * x - 4 * x + y * y - y - x * y
}
}

// construct an optimization problem
val problem: C2OptimProblem = C2OptimProblemImpl(f)

// Optimizes a multivariate function using Nelder-Mead's method.
val solver = NelderMeadMinimizer(
1e-15, // epsilon
20) // max number of iterations
val soln: NelderMeadMinimizer.Solution = solver.solve(problem)
// initial guesses for minima of f
val x0: Array = arrayOf(
DenseVector(0.0, 0.0),
DenseVector(1.2, 0.0),
DenseVector(0.0, 0.8)
)
val nmmin: Vector = soln.search(*x0)
val fmin: Double = f.evaluate(nmmin)
println(java.lang.String.format("f(%s) = %f", nmmin.toString(), fmin))