Function Repository Resource:

ListD

Source Notebook

Find the numerical derivative of a list of values or pairs of values

Contributed by: Jon McLoone

ResourceFunction["ListD"][data]

finds the derivative of a list of data.

ResourceFunction["ListD"][data,type]

finds the derivative of a list of data using the method type.

Details and Options

Available choices for method are "Forward", "Backward", "Center" or "Fourier".
"Forward", "Backward" and "Center" all use linear fitting on a window of points with the given relative position to the point being considered.
With "WindowSize"1 the values computed by "Forward", "Backward" and "Center" are simply the quotient of differences in the values.
The "Fourier" method uses an FFT based method but is only supported for regularly spaced points.
One dimensional data is assumed to be regularly spaced with unit spacing.
ResourceFunction["ListD"] accepts the following option:
"WindowSize"1the number of extra points to use to find a linear fit

Examples

Basic Examples (2) 

Find the derivative of data sampled from a function:

In[1]:=
data = Table[Sin[2 Pi x/20], {x, 0., 20}]
Out[1]=
In[2]:=
d = ResourceFunction["ListD"][data]
Out[2]=
In[3]:=
ListPlot[{data, d}]
Out[3]=

Find the derivative of {x,y} data sampled from a function:

In[4]:=
data2 = Table[{x, Sin[x]}, {x, 0., 2 Pi, 0.2}]
Out[4]=
In[5]:=
d2 = ResourceFunction["ListD"][data2]
Out[5]=
In[6]:=
ListPlot[{data2, d2}]
Out[6]=

Scope (4) 

The default method, "Center" generates new points between each of the original x-values using values from both sides to approximate the derivative:

In[7]:=
ResourceFunction["ListD"][{{0., 0}, {1, 1}}]
Out[7]=

The method, "Forward" generates new points at each of the original x-values using the next values to determine the derivative:

In[8]:=
ResourceFunction["ListD"][{{0, 0}, {1, 1}}, "Forward"]
Out[8]=

The method, "Backward" generates new points at each of the original x-values using the previous values to determine the derivative:

In[9]:=
ResourceFunction["ListD"][{{0, 0}, {1, 1}}, "Backward"]
Out[9]=

The method, "Fourier" is appropriate for larger sets of oscillatory data:

In[10]:=
data = Table[Sin[7 Pi x/100], {x, 0., 100}];
d = ResourceFunction["ListD"][data, "Fourier"];
In[11]:=
ListPlot[{data, d}]
Out[11]=

Options (3) 

A small amount of noise in data can create significant errors in ListD:

In[12]:=
data3 = Table[{x, Sin[x] + RandomReal[{-0.1, 0.1}]}, {x, 0., 2 Pi, 0.1}];
ListPlot[{data3, ResourceFunction["ListD"][data3]}]
Out[13]=

By increasing the "WindowSize" the derivative is established by from the best local fit to the points:

In[14]:=
ListPlot[{data3, ResourceFunction["ListD"][data3, "WindowSize" -> 8]}]
Out[14]=

Smoothing the data first to remove noise has a similar effect but often produces less smooth results for the same amount of smoothing:

In[15]:=
ListPlot[{data3, ResourceFunction["ListD"][MovingAverage[data3, 8]]}]
Out[15]=

Possible Issues (1) 

The "Fourier" method is only supported for regularly sampled data:

In[16]:=
ResourceFunction["ListD"][{{0, 0}, {1, 1}, {3, 1}}, "Fourier"]
Out[16]=

Publisher

Jon McLoone

Version History

  • 1.0.1 – 01 April 2022
  • 1.0.0 – 28 March 2022

Related Resources

License Information