# NMinimize and DE

I would like to use the Differential Evolution option of NMinimize to find the "optimal" solution for the hyper-sphere function defined as follows,

f[1] = Compile[{{x, _Real, 1}}, Total[x^2]];


The input for the function is a vector of D real-valued components that are constrained by -100 and 100.

Is it possible to solve this (or similar) problem using NMinimize?

Many thanks.

• Yes, I think it is. Of course, as I read the problem, the minimum is 0. and the use of NMinimize is unnecessary. (Perhaps more detail, or a nontrivial example, would help you get more help, if this comment is unsatisfactory.) May 28 at 17:00
• Example: Block[{f, d = 99, vars, x}, vars = Array[x, d]; f[1] = Compile[{{x, _Real, 1}}, Total[x^2], RuntimeOptions -> {"EvaluateSymbolically" -> False, "WarningMessages" -> False}]; NMinimize[{f[1][vars], Thread[-100 < vars < 100]}, vars, Method -> "DifferentialEvolution"] ] May 28 at 17:06
• Thank you so much. I agree the Sphere function is trivial but I just wanted to know how to use NMinimize with vectors and you have explained to me. Many thanks! May 28 at 18:26
• You're welcome. This is pretty much the same problem, with a variation on the solution: mathematica.stackexchange.com/questions/125379/… May 28 at 19:25