# How to find global minimum of function depending on list

For example I have a function for simplicity

F[x_]:= x[]^2 + x[]^2 + ...(some function of x as a vector)


How to minimize this function using NMinimize (without using separate variables {x,y,z...}, but using x itself as a vector)

You can use a syntax like this to specify that your variable is a vector:

NMinimize[Norm[x], x ∈ FullRegion]

{1.05304*10^-8, {x -> {-7.46531*10^-9, -7.10577*10^-9, -2.16042*10^-9}}}


Use Indexed to access specific components of the vector. E.g.,

NMinimize[Indexed[x,1]^2 + Indexed[x,2]^4, x ∈ FullRegion]


When doing this with more complicated functions, it may be necessary to define them in a way so that they won't evaluate for non-vector arguments. Use _?VectorQ in the argument pattern. Test your function with a single symbolic argument to make sure it doesn't evaluate to anything undesirable.

Example:

This is incorrect:

Clear[f]
f[vec_] := vec[]^2 + vec[]^2 Even though it "works", trying to take the part of a symbol is an error. More complex cases that allow such sloppiness will fail completely at best, and give you wrong results at worst.

This is correct:

Clear[f]
f[vec_?VectorQ] := vec[]^2 + vec[]^2


The following is a very simple implementation of what you have requested

F[x_] := x[]^2 + x[]^2 + Cosh[x[] - 2]
X = Table[x[i], {i, 1, 4}];
NMinimize[F[X], X]
(* {1., {x -> -5.00268*10^-9, x -> -6.20339*10^-9,
x -> 1.04214, x -> 2.}} *)


It might be simpler to write your function directly in terms of x, x,..., but that is up to you.