NMinimize cant find solutions for a function which clearly has one. Setting a working precision resulted in some output, however with error messages about tolerance and precision.
Heres my code. The issue is with the function \[Delta]Funcnew
. If its replaced with \[Delta]Func
, NMinimize runs with no problem. In fact, the result from using \[Delta]Func
are also valid initial points while using \[Delta]Funcnew
, since it introduces no change in the constraints.
(* Initialization values*)
mu3 = 2 10^-04;
eps = 1 10^-15;
fEC = 116/100;
nb = 10^11;
qx = 1/2;
dB = 0;
mu1 = 4/10; mu2 = mu3 + 10^-3;
mu = {mu1, mu2, mu3};
pmu1 = 1/4; pmu2 = 1/4; pmu3 = 1 - pmu1 - pmu2;
pmu = {{pmu1, pmu2, pmu3}, {pmu1, pmu2,
pmu3}};(*prob of intensity in bases;{x,z}*)
m = 20;(*number of photons considered*)
epstrunc = 10^-15;
epshoeff = 10^-15;
epschern = 10^-15;
nxvec = {2060502229, 7499251, 2507257};
nx = Total[nxvec];
nz = 2070508737;
(* Functions*)
chernofFunc[Num_,
p_, \[Epsilon]_] := -Log[\[Epsilon]] (1 +
Sqrt[1 - (2 p Num/Log[\[Epsilon]])]);
plBFunc[l_, b_] :=
Sum[pmu[[b, j]] Exp[-mu[[j]]] mu[[j]]^l/l!, {j, Length[mu]}];
p\[Mu]lBFunc[j_, l_,
b_] := (Exp[-mu[[j]]] mu[[j]]^l/l!) (pmu[[b, j]]/plBFunc[l, b]);
qFunc[m_, b_] :=
Sum[pmu[[b, j]] Exp[-mu[[j]]] Sum[
mu[[j]]^l/l!, {l, m + 1, Infinity}], {j, Length[mu]}];
\[CapitalLambda]Func[m_, b_] :=
qFunc[m, b] qx nb + chernofFunc[qx nb, qFunc[m, b], epstrunc];
entrFunc[x_] := If[0 < x < 1,
-x*Log[2, x] - (1 - x) Log[2, 1 - x], 0
];
(* The functions in focus; Using \[Delta]Funcnew in the objective function of NMinimize causes an erro while \[Delta]Func doesnt *)
\[Delta]Func[nx_, nz_, eps_] :=
Sqrt[(nx + nz) (nx + 1) Log[1/eps]/(2 nx^2 nz)];
\[Delta]Funcnew[a_, b_, c_, d_] := Module[{aux1, aux2}, If[c == 0, 0,
If[d == 0, b,
aux1 = ((c + d)*(1 - b)*b)/(c*d*Log[2]);
aux2 = Log[2, ((c + d)/(c*d*(1 - b)*b))*(21^2/a^2)];
b + Sqrt[aux1*aux2]]]];
xconstr =
Join[Table[\[CapitalLambda]Func[m, 1] +
Exp[-mu[[j]]] pmu[[1, j]] Sum[
Subscript[nxvar, l] mu[[j]]^l/(l! plBFunc[l, 2]), {l, 0, m}] >=
nxvec[[j]] + Subscript[\[Delta]\[Mu]nx, j] >=
Exp[-mu[[j]]] pmu[[1, j]] Sum[
Subscript[nxvar, l] mu[[j]]^l/(l! plBFunc[l, 2]), {l, 0,
m}], {j, Length[mu]}],
{Sum[Subscript[\[Delta]\[Mu]nx, j], {j, Length[mu]}] == 0},
Table[
Abs[Subscript[\[Delta]\[Mu]nx, j]] <=
Sqrt[-Log[epshoeff/2] nx/2], {j, Length[mu]}],
Table[
0 <= Subscript[nxvar, l] <=
Min[plBFunc[l, 1] (qx) nb +
chernofFunc[(qx) nb, plBFunc[l, 1], epschern], nx], {l, 0, m}]];
xvars = Join[Table[Subscript[nxvar, l], {l, 0, m}],
Table[Subscript[\[Delta]\[Mu]nx, j], {j, Length[mu]}]]; NMinimize[
Join[{(Subscript[nxvar, 0] +
Subscript[nxvar,
1] (1 - entrFunc[
2 10^7/(16 10^8) +(*\[Delta]Func[nx,nz,
eps]*)\[Delta]Funcnew[eps, 2 10^7/(16 10^8), (16 10^8),
Subscript[nxvar, 1]]]))}, xconstr], xvars(*,
WorkingPrecision -> 30*)]
{1.40238*10^9, {Subscript[nxvar, 0] -> 0.0638234, Subscript[nxvar, 1] -> 1.68736*10^9, Subscript[nxvar, 2] -> 3.49431*10^8, Subscript[nxvar, 3] -> 3.01715*10^7, Subscript[nxvar, 4] -> 3.15361*10^6, Subscript[nxvar, 5] -> 389781., Subscript[nxvar, 6] -> 13573.3, Subscript[nxvar, 7] -> 1907.16, Subscript[nxvar, 8] -> 273.691, Subscript[nxvar, 9] -> 48.6293, Subscript[nxvar, 10] -> 0., Subscript[nxvar, 11] -> 62.5704, Subscript[nxvar, 12] -> 54.7271,
$\endgroup$Subscript[nxvar, 13] -> 69.0776, Subscript[nxvar, 14] -> 44.5899, Subscript[nxvar, 15] -> 24.1294, Subscript[nxvar, 16] -> 6.94956, Subscript[nxvar, 17] -> 27.6304, Subscript[nxvar, 18] -> 6.90844*10^-8, Subscript[nxvar, 19] -> 57.727, Subscript[nxvar, 20] -> 59.6788, Subscript[\[Delta]\[Mu]nx, 1] -> -2.40772, Subscript[\[Delta]\[Mu]nx, 2] -> 2.43697, Subscript[\[Delta]\[Mu]nx, 3] -> -0.029244}}
which does not satisfy the constraints: $\endgroup$xconstr /. {Subscript[nxvar, 0] -> 0.06382342380843865
, Subscript[nxvar, 1] -> 1.6873584725403113*^9, Subscript[nxvar, 2] -> 3.494310091122603
*^8, Subscript[nxvar, 3] -> 3.017146879529025*^7, Subscript[nxvar, 4] -> 3.1536058246530266
*^6, Subscript[nxvar, 5] -> 389781.3607272387, Subscript[nxvar, 6] -> 13573.263892907693
, Subscript[nxvar, 7] -> 1907.1605181443365, Subscript[nxvar, 8] -> 273.690670123168
, Subscript[nxvar, 9] -> 48.62931849893684, Subscript[nxvar, 10] -> 0.
,` $\endgroup$Subscript[nxvar, 11] -> 62.5704125099421
, Subscript[nxvar, 12] -> 54.727084251219274, Subscript[nxvar, 13] -> 69.07757076407856
, Subscript[nxvar, 14] -> 44.58985988873386, Subscript[nxvar, 15] -> 24.129427864829065
, Subscript[nxvar, 16] -> 6.949561997617705, Subscript[nxvar, 17] -> 27.630390124413843
, Subscript[nxvar, 18] -> 6.908441791607433*^-8, Subscript[nxvar, 19] -> 57.72700075845685
, Subscript[nxvar, 20] -> 59.67877636043151,
$\endgroup$Subscript[\[Delta]\[Mu]nx, 1] -> -2.4077232487594733
, Subscript[[Delta][Mu]nx, 2] -> 2.436967204353289, Subscript[\[Delta]\[Mu]nx, 3] -> -0.02924395559381554}
results in{False, False, False, False, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True}
$\endgroup$