0
$\begingroup$

Why does NMinimize throw the error and how to fix it?

ClearAll["Global`*"]

eq[chi_, t_, a_, b_, gamma_, beta_] := 
  a*(t - 315)*(chi)^(1/gamma) + 
   b*(chi)^(1/gamma + 1/beta)*1000^(1/beta) - 1;

Chi[t_, a_, b_, gamma_, beta_] := 
 NSolve[eq[chi, t, a, b, gamma, beta] == 0, chi, Reals][[1, 1, 2]]

Chi[155, 0.7, 0.008, 1.6, 0.5]

(*0.12029*)

min[a_, b_, gamma_, 
  beta_] := (Chi[131, a, b, gamma, beta] - 62)^2

min[0.7, 0.008, 1.6, 0.5]

(*3828.06*)

NMinimize[Evaluate@min[a, b, gamma, beta], {a, b, gamma, beta}]

(*During evaluation of In[7]:= 
ToBoxes[Refresh[Internal`MessageMenu["NSolve", "nsmet", 2, 7, 1, 34328787444913064695, "Local"], None], StandardForm]NSolve::nsmet: This system cannot be solved with the methods available to NSolve.*)
$\endgroup$
6
  • 1
    $\begingroup$ WHen typing min[a,b,gamma,beta] Mathematica says NSolve::nsmet: This system cannot be solved with the methods available to NSolve. !Mathematica graphics which is what you also show at the end. So need to solve this problem first before NMinimize can work $\endgroup$
    – Nasser
    Commented Oct 9, 2023 at 8:41
  • $\begingroup$ @Nasser, thanks for the comment! But I don't understand, what is the wrong with the function min[a,b,gamma,beta]? NSolve return chi for example in this case min[0.7, 0.008, 1.6, 0.5] $\endgroup$
    – Mam Mam
    Commented Oct 9, 2023 at 10:05
  • 1
    $\begingroup$ But min[0.7,0.008,1.6,0.5] and min[a,b,gamma,beta] are not the same? First case you are passing numerical values, in the second you are not. NDSolve sees the equation to solve as -1+1000^(1/beta) b chi^(1/beta+1/gamma)-184 a chi^(1/gamma)==0 in the second case, while in the first case it sees the equation as -1-128.8 chi^0.625+8000. chi^2.625==0 that is the difference. $\endgroup$
    – Nasser
    Commented Oct 9, 2023 at 10:33
  • $\begingroup$ @Nasser, thanks! Yes, I agree, but doesn't NMinimize substitute certain variable values into the function min[a,b,gamma,beta]? $\endgroup$
    – Mam Mam
    Commented Oct 9, 2023 at 10:41
  • 1
    $\begingroup$ The issue is that NSolve is called before NMinimize sees the input. So it is NSolve that is generating the error, not NMinimize. $\endgroup$
    – Nasser
    Commented Oct 9, 2023 at 10:45

0