diff_test, a MATLAB code which calls diff(), which computes differences in a vector of data, which can be scaled to estimate derivatives of equally spaced data.
The diff() function is built in to MATLAB. If y is a vector of n data values, then diff(y) is the vector of n-1 differences of consecutive pairs of data. If the y values were computed at evenly spaced x values, then each entry of diff(y)/h is an approximation to the derivative of y(x) at the midpoint of the corresponding pair of consecutive x values.
Again, if equal spacing is used in x, diff(y,1)/h, diff(y,2)/h^2, and diff(y,3)/h^3 are vectors of length n-1, n-2, and n-3 that approximate first, second and third derivatives of y(x).
The computer code and data files described and made available on this web page are distributed under the MIT license
diff is available in a MATLAB version.
diff_center, a MATLAB code which interactively uses centered differences to estimate the derivative of a function f(x), using a stepsize h.
diff_forward, a MATLAB code which interactively uses forward differences to estimate the derivative of a function f(x), using a stepsize h.
diff2_center, a MATLAB code which interactively uses centered differences to estimate the second derivative of a function f(x), using a stepsize h.