Numerical derivative of an array

I have an array of doubles I’d like to compute the second derivative of. I’ve poked around on the forums/documentation for a little while, and it seems like ROOT doesn’t support numerical differentiation of an array in ways that other platforms do (Matlab for example). Is this true, and if so, are there any suggestions for a work around? Thanks in advance.

ROOT Version: 6.16.00
Platform: Debian
Compiler: g++

Hello Samuel,

Indeed I don’t think we provide anything out of the box in ROOT, but I am sure several examples online can be used in C++ or Python. Once this is done, the result will be directly usable in ROOT!


I typically use the central finite difference method:

double arr[N];
//Initialize here your array "arr"
double d1[N]{};
double d2[N]{};
const double step = 1.; // bin width
for(size_t i=1; i<N-1;++i) {
    d1[i] = (arr[i+1] - arr[i-1])/(2.*step);
    d2[i] = (arr[i+1] + arr[i-1] - 2*arr[i])/step;
1 Like