# How to find the regions for which the derivative of my function changes sign?

I have an energy function of the angles of the electrons' spins. th1 is vector with (2l+2) elements and each element represents the angle of an individual electron spin. I need to eventually find the angles for which my energy is minimum. (I can use NMinimize but I want to make sure that my answer is the Global minimum, so I want to figure out the derivative first and see how many minimum my function has).

So I am taking the derivative of the function, and using Reduce to find different regions, but it takes forever ant does not give me the answer. Any idea how I can find the regions for which my derivative changes sign so I can figure out where the minimums are?

  \[ScriptL]0 = 5
\[Gamma] =
Table[{Riffle[Range[0, -\[ScriptL]0, -1], Range[\[ScriptL]0]][[i]],
1}, {i, 1, 2 \[ScriptL]0 + 1}];
th1 = Table[Subscript[t, n] , {n, 1, 2 \[ScriptL]0 + 2}]
deriv = Table[1, {n, 1, 2 \[ScriptL]0 + 2}]

factorFxn[\[ScriptL]_, m1_, m2_, p1_, p2_] :=

If[\[Gamma][[p1, 1]] - \[Gamma][[m1, 1]] == \[Gamma][[m2,
1]] - \[Gamma][[p2, 1]],
Sum[(2 \[ScriptL] + 1)^2 Sum[
If[\[Gamma][[p1, 1]] - \[Gamma][[m1, 1]] ==
mval && \[Gamma][[m2, 1]] - \[Gamma][[p2, 1]] ==
mval, (-1)^(\[Gamma][[m1, 1]] + \[Gamma][[m2, 1]] +
mval) ThreeJSymbol[{\[ScriptL], -\[Gamma][[m1,
1]]}, {\[ScriptL], \[Gamma][[p1,
1]]}, {\[ScriptL]temp, -mval}] ThreeJSymbol[{\[ScriptL]temp,
mval}, {\[ScriptL], -\[Gamma][[m2,
1]]}, {\[ScriptL], \[Gamma][[p2,
1]]}] ThreeJSymbol[{\[ScriptL], 0}, {\[ScriptL],
0}, {\[ScriptL]temp, 0}]^2,
0], {mval, -\[ScriptL]temp, \[ScriptL]temp}], {\[ScriptL]temp,
0, 2 \[ScriptL]}], 0]

energy[th1_] :=(*(2 \[ScriptL]0 +1)^2*) Sum[
(* Find out which states we're calculating the matrix element of *)

(Cos[th1[[p2]]] Cos[th1[[p1]]] +
Cos[th1[[p2]]] Sin[th1[[p1 + 1]]] +
Cos[th1[[p1]]] Sin[th1[[p2 + 1]]] +
Sin[th1[[p2 + 1]]] Sin[th1[[p1 + 1]]] +
If[p1 == p2, Cos[th1[[p1]]] Sin[th1[[p1 + 1]]],
0]) factorFxn[\[ScriptL]0, m1, m2, p1, p2]

, {p1, 1, 2 \[ScriptL]0 + 1}, {m1, 1, 2 \[ScriptL]0 + 1}, {p2, 1,
p1}, {m2, 1, m1}];

derivative = Map[D[energy[th1], #] &, th1[[1 ;; 2 \[ScriptL]0 + 2]]]

th1[[1]] = 0.000001;
th1[[2 \[ScriptL]0 + 2]] = \[Pi]/2;
Reduce[derivative == 0 &&
0 < th1[[2 ;; 2 \[ScriptL]0 + 1]] <= \[Pi]/2,
th1[[2 ;; 2 \[ScriptL]0 + 1]]]

• Try Map[D[energy[th1], #] &, th1[[1 ;; 5]]] May 22 at 21:21
• Thank you so much, it gives me the derivative, Do you have any suggestions how to find the regions it changes sign? @UlrichNeumann May 22 at 21:57
• by the way, I'm not sure th1[[1]] = 0.000001 does what you might mean it to. it sets the first part of the list th1 to 0.000001; it doesn't set the symbol at that first place, i.e. Subscript[t,1] to 0.000001! for that, use Evaluate[th1[[1]]] = 0.000001. May 22 at 23:04
• (Also, for convenience, by the way, instead of using th1[[2 ;; 2 \[ScriptL]0 + 1]], you can simply use Rest[th1]!) May 22 at 23:10
• @DelaramNematollahi oh, ok. I don't think th1 appears anywhere in the following code after that assignment, though (it's already been evaluated into Subscript[t, n]'s), so this would have no effect; as such I assumed you wanted Subscript[t, 1] to have the value 0.000001. May 22 at 23:13