I need to find the minimum of a function f(t) = int g(t,x) dx over [0,1]. I used
g[t_, x_] := *huge expression*
f[t_?NumericQ] := NIntegrate[g[t, x], {x, -1, 1}]
as explained in an old thread here, but when I run
FindMinimum[f[t], t \[Element] Interval[{0,1}]]
I get as an answer
{0., {t -> 1.}}
which is not the minimum, and indeed this is followed by the message
FindMinimum::fmgz: Encountered a gradient that is effectively zero. The result returned may not be a minimum; it may be a maximum or a saddle point.
Can someone help me? What am I doing wrong? Thanks!
EDIT: I was trying to keep it short (and similar in notation to the old thread), but the full expressions look like
g[t_,q_, u_, OptionsPattern[]] := Module[{k=OptionValue[k],*other parameters*}, *function of t,q,u,parameters*]
Options[g] = {k -> 3,*other default parameters*};
f[t_?NumericQ] := NIntegrate[g[t, q, u], {u, 0, \[Infinity]}, {q, 0, \[Infinity]}, Method -> "QuasiMonteCarlo", MaxPoints -> 10^5, AccuracyGoal -> \[Infinity]];
NIntegrate
. 2) Try usingNMinimize
(with different methods) and see do you get an answer you expect. $\endgroup$ – Anton Antonov Dec 25 '20 at 13:31FindMinimum[Abs[2 x - 1] + Abs[x^2 - 1], {x, -2, 2}, Method -> "PrincipalAxis"]
$\endgroup$ – Michael E2 Dec 26 '20 at 16:38