Hello,
I have encountered a weird behavior of NMinimize for discontinuous functions. Consider the following piece of code:
f[x_] := Piecewise[{{0, 0 <= x <= Pi/3}, {Pi/3,
Pi/3 < x <= 2 Pi/3}, {2 Pi/3,
2 Pi/3 < x <= 3 Pi/3} , {3 Pi/3,
3 Pi/3 < x <= 4 Pi/3}, {4 Pi/3, 4 Pi/3 < x <= 5 Pi/3}, {5 Pi/3,
5 Pi/3 < x <= 6 Pi/3} }]
parameters = Flatten[Table[c[i], {i, 1, 5}]];
constraints = Flatten[Table[0 <= c[i] <= 2 Pi, {i, 1, 5}]];
CycleConstr = {c[1] == c[5]};
NMinimize[{Sum[
Cos[c[i]] (Cos[f[c[i]]] - Cos[f[c[i + 1]]]) +
Sin[c[i]] (Sin[f[c[i]]] - Sin[f[c[i + 1]]]), {i, 1, 4}],
constraints, CycleConstr}, parameters]
The output: {0., {c[1] -> 3.47562, c[2] -> 3.58266, c[3] -> 4.15874, c[4] -> 3.52307, c[5] -> 3.47562}}
However, it is easy to check that the minimum is -1, which the direct substitution shows
Simplify[Sum[
Cos[c[i]] (Cos[f[c[i]]] - Cos[f[c[i + 1]]]) +
Sin[c[i]] (Sin[f[c[i]]] - Sin[f[c[i + 1]]]), {i, 1, 4}] /. {
c[1] -> Pi/3,
c[2] -> 2 Pi/3,
c[3] -> 3 Pi/3,
c[4] -> 5 Pi/3,
c[5] -> Pi/3
}]
I would like to play with the above example. So if anyone has any thoughts how to find the minimum with Mathematica functions, I would very much appreciate.