I have a very complicated function of one variable consisting of exponential and error functions combined in various ways. Mathematica can't take the derivative of this function in the usual way (using prime or D) because it makes use of the function Im. Following the discussion here, I decided to use the limit definition of the derivative instead of prime or D:

dn[\[Delta]_] = Assuming[Element[\[Delta], Reals], Limit[(Realn[(\[Delta] + \[CurlyEpsilon])] - Realn[\[Delta]])/\[CurlyEpsilon], \[CurlyEpsilon] -> 0]];

This works for the first derivative, but returns a function which is infinity everywhere for the second derivative:

ddn[\[Delta]_] = 
  Assuming[Element[\[Delta], Reals], 
   Limit[(Realn[(\[Delta] + \[Xi])] - 2*Realn[\[Delta]] + 
       Realn[(\[Delta] - \[Xi])])/\[Xi]^2, \[Xi] -> 0]];

at any point. While trying to debug this problem, I discovered that multiplying the numerator and the denominator in the definition of the first derivative by 2 causes it too to give a function which is infinity at all points:

dn[\[Delta]_] = Assuming[Element[\[Delta], Reals], Limit[(2 Realn[(\[Delta] + \[CurlyEpsilon])] - 2 Realn[\[Delta]])/(2 \[CurlyEpsilon]), \[CurlyEpsilon] -> 0]];

and which I am utterly unable to explain. I can do both derivatives numerically using a finite number of points, and the results look reasonably well-behaved (i.e finite and smooth) within the region where the function is varying (it approaches zero at both infinities). Besides, the function made by summing terms which are all infinitely differentiable, so I don't see why the analytical method doesn't work...


closed as off-topic by Jens, ilian, rcollyer, Bob Hanlon, MarcoB Aug 11 '15 at 18:37

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question cannot be answered without additional information. Questions on problems in code must describe the specific problem and include valid code to reproduce it. Any data used for programming examples should be embedded in the question or code to generate the (fake) data must be included." – Jens, ilian, rcollyer, Bob Hanlon, MarcoB
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ I can't reproduce your problem when setting for example Realn[x_]:=Re[Gamma[I x]]. Could you add an example that shows the issue? $\endgroup$ – Jens Aug 10 '15 at 23:19
  • $\begingroup$ I don't know how to produce a function that reproduces the error and that can be shared here. Even copying straight from mathematica's output doesn't work, and produces a function that mathematica won't compute the limit of at all. I suspect that this is due to needing arbitrary precision in some of the coefficients for everything to work. (In fact mathematica won't even plot the function copied from the output.) $\endgroup$ – Mat6554 Aug 11 '15 at 15:22
  • $\begingroup$ If it works for Jens's example and not for yours, I've got to think that the problem has to do with something specific in your function. Any chance of narrowing it down to an example that can be shared? $\endgroup$ – Michael E2 Aug 11 '15 at 17:44