# Finding multiple local minimum

I have the following code:

sol = NDSolve[{v1'[t] ==
16.5*(v2[t] -
v1[t] - (-0.714*v1[t] +
0.5*(-1.143 + 0.714)*(Abs[v1[t] + 1] - Abs[v1[t] - 1]))),  v2'[t] == v1[t] - v2[t] + i[t], i'[t] == -35*v2[t], v1[0] == 0.7,  v2[0] == 0, i[0] == 0}, {v1, v2, i}, {t, 0, 100}]
V1[t_] = v1[t] /. sol
Plot[V1[t], {t, 0, 100}, PlotRange -> All, AxesLabel -> {"t", "V1"}]
FindMinValue[V1[t], t]


So my problem is that I would need the value of every local minimum of this oscillating function. I tried reading these forums, but I'm a newbie to mathematica, so some explanations were beyond my understanding. Can you give me some hints or help, so I can get the values of the minimums? I have 7.0 version.

To find the values for the v1 minima we can proceed as follows

T = {};
sol = NDSolve[{v1'[t] == 16.5*(v2[t] - v1[t] - (-0.714*v1[t] + 0.5*(-1.143 + 0.714)*(Abs[v1[t] + 1] - Abs[v1[t] - 1]))),
v2'[t] == v1[t] - v2[t] + i[t],
i'[t] == -35*v2[t],
v1[0] == 0.7,
v2[0] == 0,
i[0] == 0,
WhenEvent[v1'[t] == 0, If[v1[t] < 1.5, AppendTo[T, {t, v1[t]}]]]}, {v1, v2, i}, {t, 0, 100}]


so in T we will have all the minima locations.

V1[t_] = v1[t] /. sol
gr1 = Plot[V1[t], {t, 0, 100}, PlotRange -> All, AxesLabel -> {"t", "V1"}]
gr2 = ListPlot[T, PlotStyle -> Red];
Show[gr1, gr2]


• Thank you! I saw you put v1[t]<1.5 in the logical expression of the 'If' command. Can you tell me, why can't I use v1''[t]>0? If I'm right, that is a criterion for a minimum in function analysis, I tried to add it, but that way it doesn't find any minimum. Nov 20, 2020 at 17:19
• In the equation for v1 as v1'[t] = f(v1[t],v2[t]) if f(.) were derivable regarding t then we could write the condition as WhenEvent[v1'[t]==0,If[H > 0,Append[...]]] where H = D[f(v1[t],v2[t]),t] but f has inside the function Abs[] .... Nov 20, 2020 at 18:41
• But @SirAndre66 , be aware, that the minima beyond t > 35, you get this way with MachinePrecision, are totaly wrong. for comparison //Rationalize[#,0]&  the equations and apply WorkingPrecision -> 50  to see the difference. (may be MaxSteps -> 10^5  ) Nov 22, 2020 at 6:13
• to @Cesareo , please see comment above. Nov 22, 2020 at 6:26

I don't have access to version 7 so I cannot verify that this will work; however, I believe that it will.

Clear["Global*"]

sol = NDSolve[{v1'[t] ==
16.5*(v2[t] -
v1[t] - (-0.714*v1[t] +
0.5*(-1.143 + 0.714)*(Abs[v1[t] + 1] - Abs[v1[t] - 1]))),
v2'[t] == v1[t] - v2[t] + i[t], i'[t] == -35*v2[t], v1[0] == 0.7,
v2[0] == 0, i[0] == 0}, {v1, v2, i}, {t, 0, 100}][[1]];


V1 should be restricted to numeric arguments

V1[t_?NumericQ] := v1[t] /. sol;

tmax = 100;


Using brute force search, the local minimum in the interval {0, tmax} are

pts = Sort[{t /. #[[2]], #[[1]]} & /@
Union[N[FindMinimum[{V1[t], 0 <= t <= tmax}, {t, #},
WorkingPrecision -> 15]] & /@ Range[0, tmax, 1/10],
SameTest -> (Abs[#1[[2, 1, -1]] - #2[[2, 1, -1]]] < 10^-3 &)]] // Quiet;


The brute force search resulted in many duplicates so they were removed with Union. Looking at the first few results

pts[[1 ;; 5]]

(* {{5.40409*10^-7, 0.700001}, {1.16966, 0.906126}, {2.52891,
0.239197}, {3.92568, -0.137409}, {5.20191, 0.6936}} *)


The Plot with the minimums highlighted:

Plot[V1[t], {t, 0, tmax},
PlotRange -> All,
AxesLabel -> {"t", "V1"},
PlotPoints -> 200,
MaxRecursion -> 7,
Epilog -> {Red, AbsolutePointSize[4], Point[pts]},
ImageSize -> Large]


• Thank you for your detailed answer, it works on 7.0 also, but it runs for a very long time, I have 12.0 on my office computer and it takes about 30 seconds. Nov 20, 2020 at 17:21
• I arbitrarily choose a very dense sampling, i.e., Range[0, tmax, 1/10]; however, this is overkill for this specific function. It will go faster if you take larger steps, e.g., Range[0, tmax, 1/2]`; however, as you increase the step size you need to check that you are not missing any of the local minima. Nov 20, 2020 at 17:49