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$
5
  • $\begingroup$ After undescribed edit by MichaelE2 (This is not a good practice.) the code in the edited question produced {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$
    – user64494
    Commented May 19 at 7:04
  • $\begingroup$ 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$
    – user64494
    Commented May 19 at 7:06
  • $\begingroup$ 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$
    – user64494
    Commented May 19 at 7:06
  • $\begingroup$ 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$
    – user64494
    Commented May 19 at 7:07
  • $\begingroup$ 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$
    – user64494
    Commented May 19 at 7:08

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$
1
  • $\begingroup$ The same result after MichaelE2's edit of the question.. $\endgroup$
    – user64494
    Commented May 19 at 6:50

Your Answer

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