Mathematica has two ways to integrate:
But what about
Derivative are for symbolic differentiation.
How can I differentiate numerically?
There is another possibility, and that is to differentiate an
Here is an example of a rather poorly behaving function whose derivative we can recover by this technique. The transfer function of a Butterworth filter looks like
The symbolic derivative of this thing, which is group delay for the filter, bogusly produces
We can get a better-behaved function by adding
But now we have a "dimple" where we had the branch cut, and, sure enough,
Build an interpolation function from it:
and differentiate that (notice carefully the tick mark in the following expression, a convenient shorthand for derivatives of functions of single variables):
As others mentioned, there's the
It's a bit less widely known that
Let's create a numerical black box function:
Update: Please also see a discussion by @acl concluding that the difference between
There are two rather different scenarios for numerical derivatives:
For scenario 1, here is an example function and its derivative:
For scenario 2, here I discretize the above function to get a table of values in some interval:
Now the derivative can be taken using
Here, I took the list
After doing the derivative, I remove the padding by using a negative argument in
Both approaches are easily generalized; the Lanczos method can be generalized to arbitrary integer-order derivatives, and the Cauchy method can be generalized to arbitrary complex-order derivatives. I won't be discussing these generalizations further in this answer, tho.
It's not too hard to implement the Richardsonian method I alluded to in my MO answer, but the routine is somewhat longer; I'll edit this answer to include it if there's interest.