Given a vector of nodes x, a point of interest xi, and a nonnegative order of derivative m, this function returns weights such that an inner product with the values f(x) returns an approximation to f^(m)(xi). Based on the recursive formula due to Fornberg (A Practical Guide to Pseudospectral Methods, Cambridge University Press).
Examples from the file:
% First derivative near a boundary
h = 0.4; x = h*(0:5)';
w = fdweights(x(2),x,1)
[ w'*exp(x) exp(x(2)) ]
x = [0 0.25 1 1.5 2.5]';
w = fdweights(0.5,x,0)
[ w'*sin(x) sin(0.5) ]
"Order" can be a slippery concept when the points are not equally spaced and so refined. That said, if their spacing is scaled to zero uniformly, the order of accuracy will be at least (# of nodes) - (order of derivative) for sufficiently smooth functions. This can increase with symmetry (e.g., centered approximations to the second derivative).
Not bad, but it could be better. I like that it has an H1 line, it has examples of use, good help, useful internal comments, plus a reference.
What did I want to see? I always look for error checks, to verify the arguments are meaningful - there were no error checks. But most importantly, I wanted to see some indication of the order of these approximations. Will these be first order approximations or second order? (This is distinct from derivative order of course.) This documentation was totally lacking. Even better would be to provide the user with a parameter that would allow them to control that order of approximation.