I have a routine which repeatedly calls FindMaximum to find the local maxima of f[m,a,b,c] as a function of m only (i.e. considers a,b,c as fixed and then finds the values of m for which the function is a local max).

I know that the FindMaximum algorithm uses Derivative[1,0,0,0][f]. Does this mean that Mathematica will recalculate the derivative every time FindMaximum is called? If so,

  1. Is there any way to avoid this (e.g. define explicitly a function equal to Derivative[1,0,0,0][f][m,a,b,c] and get Mathematica to use this function rather than calculating the derivative every time)?
  2. If (1.) is feasible, given that I expect a run of the routine to call FindMaximum several thousand times, would it represent a significant time saving?

If it helps, the function is

f[m_,a_,b_,c_]:=(Exp[a(m-b)]+1)^(-1) - c(2+m)/3 + c ((1-m^2)/3)^(1/2)

and the routine calls FindMaximum twice for each value of the parameters a,b,c (starting at m=0.9 and m=-0.9 respectively).


1 Answer 1


FindMaximum knows the Gradient-Option.

So you can just plug your gradient in like


I used your function and you'll get a speedup at about 23%. (For arbitrary choosen parameters and on my machine of course)





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.