I have the function:
Energia[τ_, g_, NN_, L_, vars : {__}] /; Length[vars] == NN/2 := 1/π Sum[
(2 π)/L (-2 Cos[(2 π)/(L m)] + τ) Cos[vars[[m]]]^2,
{m, 1, NN/2}]
which depends on some parameters and a list of variables. If the list is made of 1 element only, I can evaluate it, expand it and so on without problems. Otherwise, with larger lengths I get the message that says that the function is not a number when evaluated.
In particular, I need to use Nminimize on it to find the minimum over the list and I don't know how to proceed. Do you know how to make it possible to minimize it over an arbitrary list of variables?
Edit: I still have problems even if the condition Length[vars]=NN/2
is satisfied. For example, if I try the following:
L = 200;
g = 1;
energies = List[];
For[i = 0, i < 200, i++,
ss = NMinimize[
Expand[Energia[0.0 + i 0.05, g, L/4, L,
Table[\[Theta][j], {j, 25}]]], Table[\[Theta][j], {j, 25}]];
AppendTo[energies, ss[[1]]];]
to minimize the function over the list of variables, I get error messages of the form:
NMinimize::nnum: The function value Energia[0,1,50,200, {0.870932,0.503921,0.558626,0.299901,- 0.304018,0.286253,0.335431,0.081131,0.24267,0.362557,-0.200533,0.645043,<<19>>,0.416675,-0.353446,0.627328,-0.413779,-0.39947,0.782446,-0.484861,-0.165669,0.786984,0.360874,-0.755282,0.188728}] is not a number at {\[Theta][1],\[Theta][2],\[Theta][3],\[Theta][4],\[Theta][5],\[Theta][6],\[Theta][7],\[Theta][8],\[Theta][9],\[Theta][10],\[Theta][11],\[Theta][12],\[Theta][13],\[Theta][14],\[Theta][15],\[Theta][16],\[Theta][17],\[Theta][18],\[Theta][19],\[Theta][20],\[Theta][21],\[Theta][22],\[Theta][23],\[Theta][24],\[Theta][25]} = {0.870932,0.503921,0.558626,0.299901,-0.304018,0.286253,0.335431,0.081131,0.24267,0.362557,-0.200533,0.645043,0.875082,0.416675,-0.353446,0.627328,-0.413779,-0.39947,0.782446,-0.484861,-0.165669,0.786984,0.360874,-0.755282,0.188728}.
and I don't see what I am missing exactly.