There are some peculiar things to be discovered in derivatives of some standard functions in MMA:
Strange behaviour
Example 1: Abs
We have
Abs[0.1]
(* Out[72]= 0.1 *)
But
Abs'[0.1]
(* Out[73]= Derivative[1][Abs][0.1] *)
Same thing if we avoid writing the prime:
D[Abs[x], x] /. x -> 0.1
(* Out[110]= Derivative[1][Abs][0.1] *)
That is, the derivative of Abs[] has no numerical value.
When plotted, there's nothing to be seen.
The derivative should of course be, or at least behave like, Sign[x] .
Example 2: Sign
Sign[0.1]
(* Out[78]= 1 *)
Sign'[0.1]
(* Out[79]= Derivative[1][Sign][0.1] *)
That is, the derivative of Sign[] has no numerical value.
When plotted, there's nothing to be seen.
Example 3: Floor
Floor[0.1]
(* Out[80]= 0 *)
But which value has the derivative at 0 ?
First possibility:
Floor'[0]
(* Out[89]= Derivative[1][Floor][0] *)
No value.
Second possibility:
Floor[0.]
(* Out[90]= 0 *)
Hence the numerical value seems to be 0.
No, bad luck, wrong guess! Look at that
Third possibility:
N[Floor'[0]]
(* Out[93]= 36.2120995105236639865598801739718338716778459859 *)
Furthermore:
Table[{x, N[Floor'[x], 5]}, {x, 0, 1/2, 0.05}]
(* Out[96]= {{0., 36.212}, {0.05, 12.5946}, {0.1, -4.29432}, {0.15,
1.61679}, {0.2, -0.532708}, {0.25, 0.13901}, {0.3, -0.0263362}, {0.35,
0.00318987}, {0.4, -0.000184538}, {0.45, 0.}, {0.5, 0.}} *)
Strange ocillatory behaviour for a quantity which should be = 0 throughout. It seems to be defined via a Fourier series.
Remedy ?: do it yourself !
Finally, let's create the derivative by ourselves as it is originally defined:
floorPrime[x_] := Limit[(1/h) (Floor[x + h] - Floor [x]), h -> 0]
Plot[0.1 + floorPrime[x], {x, -1, 1}, PlotRange -> {0, 0.2}]
(* Picture snipped *)
absPrime[x_] := Limit[(1/h) (Abs[x + h] - Abs[x]), h -> 0]
Plot[absPrime[x], {x, -1, 1}, PlotRange -> {-2, 2}]
(* Picture snipped *)
Ok, everything fine.
But why has MMA such problems with its own standard operation ' (or D[]) in this class of functions? Please explain.
Edit 15.09.14
There has been quite a lot of discussion here but no answer. I gather that the answers to similar topics referenced in the comments here are considered sufficient. These are:
Derivative of real functions including Re and Im
Symbolic derivatives are being calculated numerically
Because these references are pretty comprehensive I don't know if my question has contributed anything new, and the surprise was only on my side.
Let me nevertheless add some further observations which show that in some cases the documentation points out Possible Issues. But this is not done consistently. In one case WolframAlpha gives the expected result which MMA has refused to give.
1a) Abs'[0.1] is not evaluated.
But WolframAlpha "knows better":
WolframAlpha["Abs'[0.1]"];
(* -> 1 *)
1b) Trying to tell Mathematica that x is not complex but real (in which case the derivative is well defined)
Assuming[x \[Element] Reals, D[Abs[x], x]]
(* -> Derivative[1][Abs][x] *)
doesn't work either.
1c) Abs Possible Issues says: No series can be formed from Abs for complex arguments:
Series[Abs[x], {x, 0, 2}]
(* -> Abs[x] *)
For real arguments, a series can be found:
Series[Abs[x], {x, 0, 2}, Assumptions -> Element[x, Reals]]
$\begin{array}{ll} \{ & \begin{array}{ll} -x+O[x]^3 & x\leq 0 \\ x+O[x]^3 & \text{True} \\ \end{array} \\ \end{array}$
1d) UnitStep Possible Issues says: Differentiating Abs does not yield UnitStep:
D[Abs[t], t]
(* Derivative[1][Abs][t] *)
2) HeavisideTheta / DiracDelta Possible Issues say:
The functions UnitStep and HeavisideTheta are not mathematically equivalent:
{HeavisideTheta[x], UnitStep[x]}
Integrate[D[%, x], x]
(* -> {HeavisideTheta[x], UnitStep[x]} *)
Only HeavisideTheta gives DiracDelta after Differentiation.
{HeavisideTheta[x], UnitStep[x], (Sqrt[x^2]/x + 1)/2, (Abs[x]/x + 1)/2};
D[%, x] // Together
$\left\{\text{DiracDelta}[x], \begin{array}{ll} \{ & \begin{array}{ll} \text{Indeterminate} & x==0 \\ 0 & \text{True} \\ \end{array} \\ \end{array} ,0,\frac{-\text{Abs}[x]+x \text{Abs}'[x]}{2 x^2}\right\}$
3) Conjugate Possible Issues says: Differentiating Conjugate is not possible:
D[Conjugate[t], t]
(* Derivative[1][Conjugate][t] *)
A similar remark should be placed in the documentation under Possible Issues consistently.
4) Sign' behaves similar as Abs'
Sign'[0.1]
(* Derivative[1][Sign][0.1] *)
WolframAlpha["Sign[0.1]"];
(* -> 1 *)
Regards, Wolfgang
NDas defined theNumericalCalculuspackage. – Mark McClure Sep 12 '14 at 08:44Dworks in the complex domain and these functions are not differentiable in that context. That, quite simply, is the explanation of the behavior you see. Now, whether you would prefer different behavior and how you might implement it is a different question. – Mark McClure Sep 12 '14 at 09:05ReandIm. While those functions are obviously meant to work in the complex realm, I think an understanding of what is going on there is relevant. This discussion might help in that regard. – Mark McClure Sep 12 '14 at 09:09Dbut the general fact that symbolic computation assumes symbols are complex. Many computations performed by Mathematica must be fully understood in this context - fromSimplify[Abs[x^2]]to the apparent missing branch of the cube root inPlot[x^(1/3), {x,-1,1}]. There are exceptions, particularly theCubeRootandSurdfunctions introduced in V9 but, generally, computations are done in the complex numbers and I assure you that this is the context in which you need to explore your question. – Mark McClure Sep 12 '14 at 11:28Derivativeis not protected, so you can easily define your own DownValues: Thus,Abs'[x_] := Sign[x]; Abs'[0.5]produces1. – Mark McClure Sep 12 '14 at 11:30Plot[Derivative[f]...]uses a finite difference scheme on discrete functions, such asIntegerPart,Roundand several others. – Mark McClure Sep 12 '14 at 12:33Dper se butAbs,Floor, etc. that are defined as functions of a complex variable. ThatDtakes the complex derivative follows naturally. @Dr. Hintze, I recall reading somewhere that Mathematica makes no restriction on what the variables represent unless explicitly stated. So numeric functions are functions of a complex variable, unless the documentation or an error message states that it has to be real or an integer or whatever. – Michael E2 Sep 13 '14 at 13:31D[Abs[z], z]is permitted. I believe one can takeDof almost anything (early example:D[Plot[Sin[x], {x, 0, 2 Pi}]^2, Plot[Sin[x], {x, 0, 2 Pi}]]-- impressive and pointless at the same time). There are restrictions on what is allowed for a variable (second argument). However, theDerivativeofAbsis undefined, but still permitted. There's some wisdom in that, since you can define it to agree with the real function as Mark points out. – Michael E2 Sep 13 '14 at 14:25Dreturns the expected result. In cases where the complex and real derivatives do not agree, theDerivativeshould be undefined. – Michael E2 Sep 13 '14 at 14:27