0
$\begingroup$

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*)]

$\endgroup$

1 Answer 1

0
$\begingroup$

Too long for a comment. A feasible point can be generated as follows.

NMinimize[1, xconstr, xvars, WorkingPrecision -> 20]

{1.0000000000000000000, {Subscript[nxvar, 0] -> 7176.5494789910240361, Subscript[nxvar, 1] -> 1.6841902008116994349*10^9, Subscript[nxvar, 2] -> 3.3405210159552200068*10^8, Subscript[nxvar, 3] -> 5.1444320605350536631*10^7, Subscript[nxvar, 4] -> 499110.78130706917318, Subscript[nxvar, 5] -> 276537.96158666931358, Subscript[nxvar, 6] -> 34798.896214346565657, Subscript[nxvar, 7] -> 3193.0545082705367966, Subscript[nxvar, 8] -> 259.59950604374802828, Subscript[nxvar, 9] -> 79.246443471757467251, Subscript[nxvar, 10] -> 69.560948303569145676, Subscript[nxvar, 11] -> 68.104999181827910212, Subscript[nxvar, 12] -> 68.133860242037516224, Subscript[nxvar, 13] -> 67.672160474038866707, Subscript[nxvar, 14] -> 67.825444892371739451, Subscript[nxvar, 15] -> 67.839751052441685080, Subscript[nxvar, 16] -> 68.890521820517016363, Subscript[nxvar, 17] -> 68.418119818292227578, Subscript[nxvar, 18] -> 68.477168791270580482, Subscript[nxvar, 19] -> 68.258049774547474756, Subscript[nxvar, 20] -> 68.671377225237488125, Subscript[\[Delta]\[Mu]nx, 1] -> 14753.570602714457514, Subscript[\[Delta]\[Mu]nx, 2] -> -8853.2064207625725962, Subscript[\[Delta]\[Mu]nx, 3] -> -5900.3641819518849183}}

Its verification

xconstr /.%[[2]]

{True,True,True,True,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$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.