Consider the following function

n = 200000`200;
k = 2 n - 50`200;
μ = 10`200^-5;
ν = 10`200^-5;
qhat = k/(2 n);

fun[s_] := 
 Log[(E^(4 n qhat s) (1 - qhat)^(-1 + 4 n μ) qhat^(-1 + 4 n ν))/
  NIntegrate[ E^(4 n qhat s) (1 - qhat)^(-1 + 4 n μ) qhat^(-1 + 4 n ν), 
             {qhat, 1/(4 n + 1), 1 - 1/(4 n + 1)},  MaxRecursion -> 12]]

I can Plot my function in order to estimate the maximum

Plot[fun[s], {s, 0, 0.2}, AxesLabel -> {"s", "P(qhat | s)"}, 
 PlotRange -> All]

enter image description here

The maximum seems to be around 0.075. Let's calculate it:

FindMaximum[fun[s], {s, 0.075}, MaxIterations -> 100]

The integrand [...] has evaluated to non-numerical values for all sampling points in the region with boundaries

Why can't I estimate the maximum with FindMaximum?

  • $\begingroup$ are defined all the constant in the fun[s] and try NMaximize[fun[s],s] $\endgroup$
    – k_v
    Commented Jan 21, 2015 at 19:02
  • $\begingroup$ @K_v Yes, all constant are defined. I edited my post to add exactly how I defined them. NMaximize[fun[s],s] doesn't work either. It returns the same error message than FindMaximum $\endgroup$
    – Remi.b
    Commented Jan 21, 2015 at 19:08

1 Answer 1


This is a recurring issue. Replace fun[s_]:= by fun[s_?NumericQ]:= to eliminate your error messages. FindMaximum then will give the answer, {9.09757, {s -> 0.0799914}}, which appears to be correct, despite the fact that FindMaximum gives the warning message that

FindMaximum::lstol: The line search decreased the step size to within the tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient increase in the function. You may need more than MachinePrecision digits of working precision to meet these tolerances."

See this Answer for a discussion of ?NumericQ.

  • 1
    $\begingroup$ Use arbitrary precision (e.g., WorkingPrecision -> 16) in FindMaximum rather than machine precision to avoid FindMaximum::lstol warning. $\endgroup$
    – Bob Hanlon
    Commented Jan 21, 2015 at 20:20
  • $\begingroup$ @BobHanlon, Good point, although it does not change the answer much: {9.097567799873060, {s -> 0.07999124376931556}}. $\endgroup$
    – bbgodfrey
    Commented Jan 21, 2015 at 20:35

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.