Options (16)
Method (2)
Use the default Method→"EulerSum" when expr is not analytic in the neighborhood of x0:
Check:
An incorrect answer is obtained with Method→NIntegrate:
Here is a derivative where the default method works poorly:
The correct answer is:
In this case the expression is analytic, so Method→NIntegrate will work well:
Scale (3)
Use Scale→s to capture the region of variation:
The scale of variation is around .01:
A value of Scale→s that is too large can be compensated by increasing the number of terms:
Use Scale to specify directional derivatives. The left and right derivatives of the nonanalytic function |x|:
Check:
Complex directions may also be specified:
Check:
Use the option Scale to avoid regions of nonanalyticity when the method used is NIntegrate:
Shrinking the radius avoids the essential singularity at x⩵1:
Check:
Terms (5)
Increasing the number of terms may improve accuracy. Here is a somewhat inaccurate approximation:
Check:
Increasing the number of terms produces a more accurate answer:
Increasing the number of terms further can produce nonsense due to numerical instability:
Combining an increase in the number of terms with a higher working precision often will reduce the error:
WorkingPrecision (6)
High-order derivatives with Method→"EulerSum" experience significant subtractive cancellation:
Using a higher working precision and additional terms produces an accurate answer:
For this problem, Method→NIntegrate with default options produces a correct answer:
Higher-order derivatives will again experience numerical instability:
Increasing WorkingPrecision will improve the accuracy:
An alternative is to increase the radius of the contour of integration:
Applications (4)
NDerivative is useful for differentiating functions that are only defined numerically. Here is such a function:
Here is the derivative of f[a,b][t] with respect to b evaluated at {a,b,t}={1,2,1}:
NDerivative can be used as an aid in developing and testing a more robust function for finding the derivative:
Check:
Properties & Relations (3)
The option Method→NIntegrate uses Cauchy's integral formula to compute derivatives:
The equivalent computation can be performed using the resource function NResidue:
The Wolfram Language has built-in code to compute derivatives of numerical functions:
The built-in numerical derivative code can be used. However, it is unable to capture the rapid oscillations:
The correct answer:
Using NDerivative with the appropriate options can compute an accurate derivative:
With Method→"EulerSum", NDerivative must be able to evaluate expr at the point x0:
Adding an additional definition for f allows NDerivative to compute the derivative:
Check:
In this case, Method→NIntegrate produces a more accurate answer: