# Minimization in mathematica [closed]

I have recently had a strange problem with NMinimize. I have a very huge function with respect to 20 parameters. When I NMinimize the function with respect to all the parameters, it gives me all the best fits and a minimum for the function. However, when I put back the value of the best fit of one of the parameters in the function and demand to minimize with respect to other parameters, it gives some different results. I guess the problem is that Mathematica is not giving me the global minimum of the parameters. My function is defined as below:

rhodata = {{0.86 + 0.78, 44.3213}, {1.25 + 0.78,
172.853}, {1.5 + 0.78, 323.546}, {1.75 + 0.78,
436.565}, {2 + 0.78, 536.288}, {2.25 + 0.78,
565.097}, {2.5 + 0.78, 689.197}, {2.75 + 0.78,
673.684}, {3 + 0.78, 675.9}, {3.25 + 0.78, 638.227}, {3.5 + 0.78,
660.388}, {3.75 + 0.78, 585.042}, {4 + 0.78,
565.097}, {4.25 + 0.78, 573.961}, {4.5 + 0.78,
447.645}, {4.75 + 0.78, 454.294}, {5 + 0.78,
363.435}, {5.25 + 0.78, 334.626}, {5.5 + 0.78,
261.496}, {5.75 + 0.78, 228.255}, {6 + 0.78,
161.773}, {6.25 + 0.78, 130.748}, {6.5 + 0.78,
95.2909}, {6.75 + 0.78, 70.9141}, {7 + 0.78,
53.1856}, {7.25 + 0.78, 28.8089}, {7.79 + 0.78, 6.6482}};

rho = Interpolation[rhodata, InterpolationOrder -> 1];
rhofinal[x_] :=
rho[x]/NIntegrate[rho[x], {x, 0.86 + 0.78, 7.79 + 0.78}];

p1term2 = NIntegrate[Sin[1.267*2.32*10^-3*473/enu]^2*rhofinal[enu], {enu, 1.64, 8.57}];
inter1p1 = Table[{w,NIntegrate[Sin[1.267*w*473/enu]^2*rhofinal[enu], {enu, 1.64, 8.57}]},{w,Table[10^w, {w, -4, -0.69897, 0.025}]}];
p1term3 = Interpolation[inter1p1];
inter2p1 = Table[{w,NIntegrate[Sin[1.267*(w - 2.32*10^-3)*473/enu]^2*rhofinal[enu], {enu,1.64,8.57}]}, {w, Table[10^w, {w, -4, -0.69897, 0.025}]}];
p1term4 = Interpolation[inter2p1];
p1forth =.;
p1forth[y_, z_,w_] := (1 -y*((1 + Sqrt[1 - z])/2)^2*p1term2 - ((1 + Sqrt[1 - y])/2)*z*p1term3[w] - ((1 - Sqrt[1 - y])/2)*z*p1term4[w])

p2term2=NIntegrate[Sin[1.267*2.32*10^-3*466/enu]^2*rhofinal[enu], {enu, 1.64, 8.57}];
inter1p2=Table[{w,NIntegrate[Sin[1.267*w*466/enu]^2*rhofinal[enu], {enu, 1.64, 8.57}]}, {w,Table[10^w, {w, -4, -0.69897, 0.025}]}];
p2term3 = Interpolation[inter1p2];
inter2p2=Table[{w,NIntegrate[Sin[1.267*(w - 2.32*10^-3)*466/enu]^2*rhofinal[enu], {enu,1.64, 8.57}]}, {w, Table[10^w, {w, -4, -0.69897, 0.025}]}];
p2term4 = Interpolation[inter2p2];
p2forth =.;
p2forth[y_, z_,w_] := (1 - y*((1 + Sqrt[1 - z])/2)^2*p2term2 - ((1 + Sqrt[1 - y])/2)*z*p2term3[w] - ((1 - Sqrt[1 - y])/2)*z*p2term4[w])

p3term2 = NIntegrate[Sin[1.267*2.32*10^-3*575/enu]^2*rhofinal[enu], {enu, 1.64, 8.57}];
inter1p3 = Table[{w,NIntegrate[Sin[1.267*w*575/enu]^2*rhofinal[enu], {enu, 1.64,8.57}]},{w,Table[10^w, {w, -4, -0.69897, 0.025}]}];
p3term3 = Interpolation[inter1p3];
inter2p3 =Table[{w,NIntegrate[Sin[1.267*(w - 2.32*10^-3)*575/enu]^2*rhofinal[enu], {enu, 1.64,8.57}]}, {w, Table[10^w, {w, -4, -0.69897, 0.025}]}];
p3term4 = Interpolation[inter2p3];
p3forth =.;
p3forth[y_, z_,w_] := (1-y*((1 + Sqrt[1 - z])/2)^2*p3term2 - ((1 + Sqrt[1 - y])/2)*z*p3term3[w] - ((1 - Sqrt[1 - y])/2)*z*p3term4[w])

p4term2 = NIntegrate[Sin[1.267*2.32*10^-3*1645/enu]^2*rhofinal[enu], {enu, 1.64, 8.57}];
inter1p4 =Table[{w,NIntegrate[Sin[1.267*w*1645/enu]^2*rhofinal[enu], {enu, 1.64,8.57}]{w, Table[10^w, {w, -4, -0.69897, 0.025}]}];
p4term3 = Interpolation[inter1p4];
inter2p4 =Table[{w,NIntegrate[Sin[1.267*(w - 2.32*10^-3)*1645/enu]^2*rhofinal[enu],{enu,1.64,8.57}]}, {w, Table[10^w, {w, -4, -0.69897, 0.025}]}];
p4term4 = Interpolation[inter2p4];
p4forth =.;
p4forth[y_, z_, w_] := (1 -y*((1 + Sqrt[1 - z])/2)^2*p4term2 - ((1 + Sqrt[1 - y])/2)*z*p4term3[w] - ((1 - Sqrt[1 - y])/2)*z*p4term4[w])

p5term2 = NIntegrate[Sin[1.267*2.32*10^-3*1645/enu]^2*rhofinal[enu], {enu, 1.64,8.57}];
inter1p5 =Table[{w,NIntegrate[Sin[1.267*w*1645/enu]^2*rhofinal[enu], {enu, 1.64,8.57}]}{w,Table[10^w, {w, -4, -0.69897, 0.025}]}];
p5term3 = Interpolation[inter1p5];
inter2p5 =Table[{w,NIntegrate[Sin[1.267*(w - 2.32*10^-3)*1645/enu]^2*rhofinal[enu],{enu,1.64,8.57}]}, {w, Table[10^w, {w, -4, -0.69897, 0.025}]}];
p5term4 = Interpolation[inter2p5];
p5forth =.;
p5forth[y_, z_,w_] := (1 -y*((1 + Sqrt[1 - z])/2)^2*p5term2 - ((1 + Sqrt[1 - y])/2)*z*p5term3[w] - ((1 - Sqrt[1 - y])/2)*z*p5term4[w])

p6term2 =NIntegrate[Sin[1.267*2.32*10^-3*1648/enu]^2*rhofinal[enu], {enu, 1.64, 8.57}];
inter1p6 =Table[{w,NIntegrate[Sin[1.267*w*1648/enu]^2*rhofinal[enu], {enu, 1.64,8.57}]},{w,Table[10^w, {w, -4, -0.69897, 0.025}]}];
p6term3 = Interpolation[inter1p6];
inter2p6 =Table[{w,NIntegrate[Sin[1.267*(w - 2.32*10^-3)*1648/enu]^2*rhofinal[enu],{enu,1.64,8.57}]}, {w, Table[10^w, {w, -4, -0.69897, 0.025}]}];
p6term4 = Interpolation[inter2p6];
p6forth =.;
p6forth[y_, z_,w_] := (1 -y*((1 + Sqrt[1 - z])/2)^2*p6term2 - ((1 + Sqrt[1 - y])/2)*z*p6term3[w] - ((1 - Sqrt[1  - y])/2)*z*p6term4[w])

M1 = 28935; M2 = 28975; M3 = 22466; M4 = 3528; M5 = 3436; M6 = 3452;
expt1 = 29616; expt2 = 29268; expt3 = 22806; expt4 = 3749; expt5 = 3763; expt6 = 3712;
B1 = 694; B2 = 697; B3 = 517; B4 = 182; B5 = 184; B6 = 174;

chi2dbforth[y_, z_, w_, epsilone_, a1_, a2_, a3_, a4_, a5_, a6_,eta1_, eta2_, eta3_,eta4_, eta5_, eta6_, epsilone1_, epsilone2_,epsilone3_, epsilone4_, epsilone5_,epsilone6_] :=
(M1-expt1*(p1forth[y, z, w])*(1 + epsilone + (0.188*a1 + 0.202*a2 + 0.109*a3 + 0.124*a4+ 0.188*a5 + 0.186*a6) + epsilone1) + eta1)^2/(M1 +B1) +
(M2 -expt2*(p2forth[y, z, w])*(1 +epsilone + (0.188*a1 + 0.202*a2 + 0.109*a3 + 0.124*a4+ 0.188*a5 + 0.186*a6) + epsilone2) + eta2)^2/(M2 +B2) +
(M3 -expt3*(p3forth[y, z, w])*(1 + epsilone + (0.188*a1 + 0.202*a2 + 0.109*a3 + 0.124*a4+ 0.188*a5 + 0.186*a6) + epsilone3) + eta3)^2/(M3 + B3) +
(M4 -expt4*(p4forth[y, z, w])*(1 +epsilone + (0.188*a1 + 0.202*a2 + 0.109*a3 + 0.124*a4+ 0.188*a5 + 0.186*a6) + epsilone4) + eta4)^2/(M4 +B4) +
(M5 - expt5*(p5forth[y, z, w])*(1 +epsilone + (0.188*a1 + 0.202*a2 + 0.109*a3 + 0.124*a4+0.188*a5 + 0.186*a6) + epsilone5) + eta5)^2/(M5 +B5) +
(M6 -expt6*(p6forth[y, z, w])*(1 +epsilone + (0.188*a1 + 0.202*a2 + 0.109*a3 + 0.124*a4 +0.188*a5 + 0.186*a6) + epsilone6) + eta6)^2/(M6+B6) +
(a1^2 + a2^2 + a3^2 + a4^2 + a5^2 + a6^2)/(0.008)^2 +
(epsilone1^2 + epsilone2^2 + epsilone3^2 + epsilone4^2 + epsilone5^+epsilone6^2)/(0.002)^2 +
eta1^2/(107)^2 + eta2^2/(107)^2 + eta3^2/(89.589)^2 + eta4^2/(19.6789)^2 + eta5^2/(19.6789)^2 + eta6^2/(19.6789)^2


I do

In[277]:= NMinimize[{chi2dbforth[y, z, w, epsilone, a1, a2, a3, a4,a5, a6, eta1, eta2, eta3, eta4, eta5, eta6, epsilone1, epsilone2,epsilone3, epsilone4, epsilone5, epsilone6], 0<= y <= 1,0 <= z <= 1, 0.0001 <= w <= 0.2, eta2 > 0, eta4 > 0, eta5 > 0}, {{y, 0, 1}, {z,0,1}, w, epsilone, a1, a2, a3, a4, a5,a6, eta1, eta2, eta3, eta4, eta5, eta6, epsilone1,epsilone2,epsilone3, epsilone4, epsilone5, epsilone6}]

Out[277]= {3.93427, {y -> 0.0973371, z -> 0.585362, w -> 0.141254, epsilone -> 0.412934,a1 -> -0.000128634, a2 -> -0.000173531,a3 -> -0.0000284711, a4 -> -0.0000792916, a5-> -0.0000690923,
a6 -> -0.0000455232, eta1 -> 0.170838, eta2 -> 1.00673, eta3 -> 0.434434, eta4 -> 0.762959, eta5 -> 0.767226, eta6 -> 0.176759, epsilone1 -> -0.000571733,
epsilone2 -> 0.000300858, epsilone3 -> 0.000283025, epsilone4 -> 0.000123856, epsilone5-> -0.000158346, epsilone6 -> 0.0000128224}}


but when for example I put back the best fit of w and minimize the function with respect to other parameters, it gives me another minimum:

In[278]:= NMinimize[{chi2dbforth[y, z, 0.1412537538707454, epsilone, a1, a2, a3, a4,   a5, a6, eta1, eta2, eta3, eta4, eta5, eta6,
epsilone1, epsilone2, epsilone3, epsilone4, epsilone5, epsilone6],0 <= z <= 1, eta2 > 0,eta4 > 0, eta5 > 0}, {{y, 0, 1}, {z, 0, 1},epsilone, a1, a2, a3, a4, a5, a6, eta1, eta2, eta3, eta4, eta5,
eta6, epsilone1, epsilone2, epsilone3, epsilone4, epsilone5,epsilone6}]

Out[278]= {2.80036, {y -> 0.185333, z -> 0.999463, epsilone -> 1.0048,a1 -> -2.02754*10^-19, a2 -> -4.84277*10^-20, a3 -> -5.448*10^-20, a4 -> -1.06784*10^-19, a5 -> - 2.03035*10^-19, a6 -> -1.31493*10^-19,
eta1 -> 52.6945, eta2 -> 7.31293*10^-9, eta3 -> -23.4955,eta4 -> 1.53328*10^-9, eta5 ->5.73679, eta6 -> -0.428075, epsilone1 -> -0.000267484, epsilone2 -> 0.00014765,
epsilone3 -> 0.000130679, epsilone4 -> 0.000084869, epsilone5 -> -0.000103317, epsilone6 -> 7.6036*10^-6}}


How can I make sure that mathematica is giving me the global minimum?

-
It will be useful if you post the complete function, not just part of it, so people can test using the same input. The solution may lie in manually tuning the optimization method. –  Szabolcs Mar 7 at 20:57
Isn't it good news that a more global minimum is more minimum than a less global one ? –  b.gatessucks Mar 7 at 20:58
The problem is that it is not just a simple function, before that I have to make 12 Tables, interpolate them, do some calculations on them, and then put them inside my main function. It is a huge thing to put here. I don't know how to put a complete code in here. –  ZKT Mar 7 at 21:00
b.gatessucks : I am expecting to get the same values. Because then I have to plot the main function with respect to one of the parameters, and to do that, I should pou different values of that parameter inside the main function, NMinimize to all other parameters, and then get the minimum of the function. So it should give me the same results. –  ZKT Mar 7 at 21:04
@ssch actually, none of the methods used by NMinimize guarantee anything at all in the sense that either convergence proofs for these heuristics are not available or pathological cases are known. Stronger statements can be made about local minimizers as implemented in FindMinimum. In practice, the success with which global minimization problems can be solved depends critically on both the problem itself and the choice of algorithm and associated tuning parameters. One cannot expect NMinimize to make these choices automatically, so in general one must supply Method` options. –  Oleksandr R. Mar 7 at 22:46
show 12 more comments

## closed as too localized by Oleksandr R., m_goldberg, halirutan, Michael E2, rm -rf♦Mar 21 at 20:36

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.