I have the following problem: I have a function enter code hereH depending on two numerical integrals g and d, Mathematica is able to draw the 3D-Plot of the function H, but it isn't able to compute NMaximize.
I know that a common problem is the argument of a function, so I tried to be as precise as possible:
g[s_, eps_, tau_] :=
NIntegrate[
x^(s - 2) Exp[-x] (1 - Cos[x tau]) Coth[x/(2 eps)], {x, 0,
Infinity}]
d[s_, eps_, tau_] :=
NIntegrate[
x^(s - 1) Exp[-x]/
2 (1 - Cos[tau x])/(1 - (Cosh[x/(2 eps )])^2), {x, 0,
Infinity}]
H[s_, eps_, tau_, d_, g_] := (2*(d)^2)/(Exp[2*g] - 1)
Mathematica doen't give me any problem with the Plot3D of H
With[{s = 1},
Plot3D[H[s, eps, tau, d[s, eps,tau],
g[s, eps, tau]] , {eps, 1, 15}, {tau, 0.1, 1},
PlotRange -> All, AxesLabel -> Automatic ]]
But when I try to find which values of tau do maximize H, it says that NIntegrate has evaluated g to non-numerical values (NIntegrate::inumr message). Here's my code:
topt[eps_] :=
With[{s = 1},
NMaximize[
H[s, eps, tau, d[s, eps, tau],
g[s, eps, tau]] , {tau} ∈
Interval[{0.2, 1}] ] ]
topt[2]
I don't get why in the Plot3D there is no problem with the numeric integration while using NMaximize Mathematica isn't able to calculate it. I looked for errors in the syntax, but I couldn't find any.
AttributesofPlot3DandNMaximize.Plot3DisHoldAllandNMaximizeis not. The difference means thatH[..]is evaluated before it is passed toNMaximize, at which pointtauis a symbol, not a number. ForPlot3D, evaluation is "held" (not done) and the code is passed toPlot3Das is; it is not evaluated untilepsandtauhave been assigned numeric values. – Michael E2 May 21 '18 at 12:19topt[2]returns an answer (after a few minutes). The messages, strictly speaking, are just warnings, not errors. – Michael E2 May 21 '18 at 12:24